From 1a3803d54a8de934e566d42f39b69e315c312d5f Mon Sep 17 00:00:00 2001 From: Anton Nikitin Date: Wed, 13 Feb 2013 05:12:58 -0500 Subject: Fix the bug in HTTP/1.1 reponse with Content-Length:0 In a multithread case one HTTP session is used for sending/receiving HTTP requests/responses in parallel. This causes wrong parsing of responses if Content-Length header is "0". The bug is reported to the erlang bug list: http://erlang.org/pipermail/erlang-bugs/2013-February/003391.html --- lib/inets/src/http_client/httpc_response.erl | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/inets/src/http_client/httpc_response.erl b/lib/inets/src/http_client/httpc_response.erl index f177aac8f2..8142eb8bce 100644 --- a/lib/inets/src/http_client/httpc_response.erl +++ b/lib/inets/src/http_client/httpc_response.erl @@ -426,7 +426,7 @@ format_response({{"HTTP/0.9", _, _} = StatusLine, _, Body}) -> format_response({StatusLine, Headers, Body = <<>>}) -> {{StatusLine, http_response:header_list(Headers), Body}, <<>>}; -format_response({StatusLine, Headers, Body}) -> +format_response({{"HTTP/1.0", _, _} = StatusLine, Headers, Body}) -> Length = list_to_integer(Headers#http_response_h.'content-length'), {NewBody, Data} = case Length of @@ -440,6 +440,20 @@ format_response({StatusLine, Headers, Body}) -> _ -> %% Connection prematurely ended. {Body, <<>>} end, + {{StatusLine, http_response:header_list(Headers), NewBody}, Data}; + +format_response({{"HTTP/1.1", _, _} = StatusLine, Headers, Body}) -> + Length = list_to_integer(Headers#http_response_h.'content-length'), + {NewBody, Data} = + case Length of + -1 -> % When no lenght indicator is provided + {Body, <<>>}; + Length when (Length =< size(Body)) -> + <> = Body, + {BodyThisReq, Next}; + _ -> %% Connection prematurely ended. + {Body, <<>>} + end, {{StatusLine, http_response:header_list(Headers), NewBody}, Data}. %%-------------------------------------------------------------------------- -- cgit v1.2.1