@@ -702,18 +702,35 @@ function _M.read_response(self, params)
702
702
703
703
-- Receive the body_reader
704
704
if _should_receive_body (params .method , status ) then
705
- local ok , encoding = pcall (str_lower , res_headers [" Transfer-Encoding" ])
706
- if ok and version == 1.1 and encoding == " chunked" then
705
+ has_body = true
706
+
707
+ local te = res_headers [" Transfer-Encoding" ]
708
+
709
+ -- Handle duplicate headers
710
+ -- This shouldn't happen but can in the real world
711
+ if type (te ) == " table" then
712
+ te = tbl_concat (te , " " )
713
+ end
714
+
715
+ local ok , encoding = pcall (str_lower , te )
716
+ if not ok then
717
+ encoding = " "
718
+ end
719
+
720
+ if version == 1.1 and str_find (encoding , " chunked" , 1 , true ) ~= nil then
707
721
body_reader , err = _chunked_body_reader (sock )
708
- has_body = true
709
- else
710
722
723
+ else
711
724
local ok , length = pcall (tonumber , res_headers [" Content-Length" ])
712
- if ok then
713
- body_reader , err = _body_reader ( sock , length )
714
- has_body = true
725
+ if not ok then
726
+ -- No content-length header, read until connection is closed by server
727
+ length = nil
715
728
end
729
+
730
+ body_reader , err = _body_reader (sock , length )
731
+
716
732
end
733
+
717
734
end
718
735
719
736
if res_headers [" Trailer" ] then
0 commit comments