diff options
author | Fredrik Gustafsson <fredrik@erlang.org> | 2013-02-28 09:39:43 +0100 |
---|---|---|
committer | Fredrik Gustafsson <fredrik@erlang.org> | 2013-02-28 09:39:43 +0100 |
commit | a77a09b807bbf3f37230b150511b79beea0d65d9 (patch) | |
tree | 04f1e1f7c7a66e592ff56ba4db5dacd8f9982f60 | |
parent | f9e7a175e7537f156d0843d0f741ad63bfc8ca2b (diff) | |
parent | 1a3803d54a8de934e566d42f39b69e315c312d5f (diff) | |
download | erlang-a77a09b807bbf3f37230b150511b79beea0d65d9.tar.gz |
Merge branch 'an/http11_content_length_zero' into master-pu
-rw-r--r-- | lib/inets/src/http_client/httpc_response.erl | 16 |
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}. %%-------------------------------------------------------------------------- |