summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Nikitin <nikitin@reksoft.ru>2013-02-13 05:12:58 -0500
committerFredrik Gustafsson <fredrik@erlang.org>2013-02-13 11:44:27 +0100
commit1a3803d54a8de934e566d42f39b69e315c312d5f (patch)
tree389108df3f6572eafec050f3a47f68e038e707ae
parentcd08400f92ec7672025bf39a458effcf33a423dc (diff)
downloaderlang-1a3803d54a8de934e566d42f39b69e315c312d5f.tar.gz
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
-rw-r--r--lib/inets/src/http_client/httpc_response.erl16
1 files changed, 15 insertions, 1 deletions
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)) ->
+ <<BodyThisReq:Length/binary, Next/binary>> = Body,
+ {BodyThisReq, Next};
+ _ -> %% Connection prematurely ended.
+ {Body, <<>>}
+ end,
{{StatusLine, http_response:header_list(Headers), NewBody}, Data}.
%%--------------------------------------------------------------------------