aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMarcus Arendt <[email protected]>2014-06-04 13:19:16 +0200
committerMarcus Arendt <[email protected]>2014-06-04 13:19:16 +0200
commitf29a78c97709ad94a4255fb5b2566b3a1b3af933 (patch)
tree4f9cec0f8b49f5192fd7c27fad3b2cad41fd2ae3 /lib
parent596f214fc0275df8b19a8b36bb7b71e6affc6bd5 (diff)
parenta027c412d7cb6cf6ad00422b7dfd8534bf8c212b (diff)
downloadotp-f29a78c97709ad94a4255fb5b2566b3a1b3af933.tar.gz
otp-f29a78c97709ad94a4255fb5b2566b3a1b3af933.tar.bz2
otp-f29a78c97709ad94a4255fb5b2566b3a1b3af933.zip
Merge branch 'scrapinghub/stream_body_with_no_content_length' into maint
* scrapinghub/stream_body_with_no_content_length: inets: Fix HTTP 1.0 body end on closed connection
Diffstat (limited to 'lib')
-rw-r--r--lib/inets/src/http_client/httpc_handler.erl5
-rw-r--r--lib/inets/test/httpc_SUITE.erl26
2 files changed, 31 insertions, 0 deletions
diff --git a/lib/inets/src/http_client/httpc_handler.erl b/lib/inets/src/http_client/httpc_handler.erl
index 612eb05358..5ae6760f08 100644
--- a/lib/inets/src/http_client/httpc_handler.erl
+++ b/lib/inets/src/http_client/httpc_handler.erl
@@ -1226,6 +1226,7 @@ handle_response(#state{request = Request,
handle_queue(State#state{request = undefined}, Data);
{ok, Msg, Data} ->
?hcrd("handle response - ok", []),
+ stream_remaining_body(Body, Request, StatusLine),
end_stream(StatusLine, Request),
NewState = maybe_send_answer(Request, Msg, State),
handle_queue(NewState, Data);
@@ -1656,6 +1657,10 @@ start_stream(_StatusLine, _Headers, Request) ->
?hcrt("start stream - no op", []),
{ok, Request}.
+stream_remaining_body(<<>>, _, _) ->
+ ok;
+stream_remaining_body(Body, Request, {_, Code, _}) ->
+ stream(Body, Request, Code).
%% Note the end stream message is handled by httpc_response and will
%% be sent by answer_request
diff --git a/lib/inets/test/httpc_SUITE.erl b/lib/inets/test/httpc_SUITE.erl
index f150cab877..c535d59b9f 100644
--- a/lib/inets/test/httpc_SUITE.erl
+++ b/lib/inets/test/httpc_SUITE.erl
@@ -94,6 +94,7 @@ only_simulated() ->
trace,
stream_once,
stream_single_chunk,
+ stream_no_length,
no_content_204,
tolerate_missing_CR,
userinfo,
@@ -393,6 +394,15 @@ stream_single_chunk() ->
stream_single_chunk(Config) when is_list(Config) ->
Request = {url(group_name(Config), "/single_chunk.html", Config), []},
stream_test(Request, {stream, self}).
+%%-------------------------------------------------------------------------
+stream_no_length() ->
+ [{doc, "Test the option stream for asynchrony requests with HTTP 1.0 "
+ "body end on closed connection" }].
+stream_no_length(Config) when is_list(Config) ->
+ Request1 = {url(group_name(Config), "/http_1_0_no_length_single.html", Config), []},
+ stream_test(Request1, {stream, self}),
+ Request2 = {url(group_name(Config), "/http_1_0_no_length_multiple.html", Config), []},
+ stream_test(Request2, {stream, self}).
%%-------------------------------------------------------------------------
@@ -1703,6 +1713,22 @@ handle_uri(_,"/single_chunk.html",_,_,Socket,_) ->
http_chunk:encode_last(),
send(Socket, Chunk);
+handle_uri(_,"/http_1_0_no_length_single.html",_,_,Socket,_) ->
+ Body = "HTTP/1.0 200 ok\r\n"
+ "Content-type:text/plain\r\n\r\n"
+ "single packet",
+ send(Socket, Body),
+ close(Socket);
+
+handle_uri(_,"/http_1_0_no_length_multiple.html",_,_,Socket,_) ->
+ Head = "HTTP/1.0 200 ok\r\n"
+ "Content-type:text/plain\r\n\r\n"
+ "multiple packets, ",
+ send(Socket, Head),
+ %% long body to make sure it will be sent in multiple tcp packets
+ send(Socket, string:copies("other multiple packets ", 200)),
+ close(Socket);
+
handle_uri(_,"/once.html",_,_,Socket,_) ->
Head = "HTTP/1.1 200 ok\r\n" ++
"Content-Length:32\r\n\r\n",