From 08c4a71c801246c66427f2a37d2f0f6de561d448 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Sat, 5 Jan 2019 22:30:10 +0100 Subject: Fix transfer-encoding precedence over content-length --- src/gun_http.erl | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) (limited to 'src/gun_http.erl') diff --git a/src/gun_http.erl b/src/gun_http.erl index 164ede8..ec459a3 100644 --- a/src/gun_http.erl +++ b/src/gun_http.erl @@ -522,22 +522,20 @@ response_io_from_headers(<<"HEAD">>, _, _, _) -> response_io_from_headers(_, _, Status, _) when (Status =:= 204) or (Status =:= 304) -> head; response_io_from_headers(_, Version, _Status, Headers) -> - case lists:keyfind(<<"content-length">>, 1, Headers) of - {_, <<"0">>} -> - head; - {_, Length} -> - {body, cow_http_hd:parse_content_length(Length)}; - _ when Version =:= 'HTTP/1.0' -> - body_close; + case lists:keyfind(<<"transfer-encoding">>, 1, Headers) of + {_, TE} when Version =:= 'HTTP/1.1' -> + case cow_http_hd:parse_transfer_encoding(TE) of + [<<"chunked">>] -> body_chunked; + [<<"identity">>] -> body_close + end; _ -> - case lists:keyfind(<<"transfer-encoding">>, 1, Headers) of - false -> - body_close; - {_, TE} -> - case cow_http_hd:parse_transfer_encoding(TE) of - [<<"chunked">>] -> body_chunked; - [<<"identity">>] -> body_close - end + case lists:keyfind(<<"content-length">>, 1, Headers) of + {_, <<"0">>} -> + head; + {_, Length} -> + {body, cow_http_hd:parse_content_length(Length)}; + _ -> + body_close end end. -- cgit v1.2.3