From f4b02cf574552f40ff354261b4c7cf02cb568212 Mon Sep 17 00:00:00 2001 From: Kirilll Zaborsky Date: Tue, 20 Jan 2015 21:06:13 +0300 Subject: inets: send correct nonstreamed response with streaming httpc_handler should respond with correct and complete responses seeing non-streamed status codes i.e. codes other than 200 or 206. --- lib/inets/test/httpc_SUITE.erl | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'lib/inets/test/httpc_SUITE.erl') diff --git a/lib/inets/test/httpc_SUITE.erl b/lib/inets/test/httpc_SUITE.erl index 2ad00bdf76..cc0fa5d4d9 100644 --- a/lib/inets/test/httpc_SUITE.erl +++ b/lib/inets/test/httpc_SUITE.erl @@ -98,6 +98,7 @@ only_simulated() -> stream_once, stream_single_chunk, stream_no_length, + stream_large_not_200_or_206, no_content_204, tolerate_missing_CR, userinfo, @@ -408,6 +409,13 @@ stream_no_length(Config) when is_list(Config) -> stream_test(Request1, {stream, self}), Request2 = {url(group_name(Config), "/http_1_0_no_length_multiple.html", Config), []}, stream_test(Request2, {stream, self}). +%%------------------------------------------------------------------------- +stream_large_not_200_or_206() -> + [{doc, "Test the option stream for large responses with status codes " + "other than 200 or 206" }]. +stream_large_not_200_or_206(Config) when is_list(Config) -> + Request = {url(group_name(Config), "/large_404_response.html", Config), []}, + {{_,404,_}, _, _} = non_streamed_async_test(Request, {stream, self}). %%------------------------------------------------------------------------- @@ -1117,6 +1125,19 @@ stream_test(Request, To) -> Body = binary_to_list(StreamedBody). +non_streamed_async_test(Request, To) -> + {ok, Response} = + httpc:request(get, Request, [], [{body_format, binary}]), + {ok, RequestId} = + httpc:request(get, Request, [], [{sync, false}, To]), + + receive + {http, {RequestId, Response}} -> + Response; + {http, Msg} -> + ct:fail(Msg) + end. + url(http, End, Config) -> Port = ?config(port, Config), {ok,Host} = inet:gethostname(), @@ -1807,6 +1828,17 @@ handle_uri(_,"/http_1_0_no_length_multiple.html",_,_,Socket,_) -> send(Socket, string:copies("other multiple packets ", 200)), close(Socket); +handle_uri(_,"/large_404_response.html",_,_,Socket,_) -> + %% long body to make sure it will be sent in multiple tcp packets + Body = string:copies("other multiple packets ", 200), + Head = io_lib:format("HTTP/1.1 404 not found\r\n" + "Content-length: ~B\r\n" + "Content-type: text/plain\r\n\r\n", + [length(Body)]), + send(Socket, Head), + send(Socket, Body), + close(Socket); + handle_uri(_,"/once.html",_,_,Socket,_) -> Head = "HTTP/1.1 200 ok\r\n" ++ "Content-Length:32\r\n\r\n", -- cgit v1.2.3