diff options
author | Kirilll Zaborsky <[email protected]> | 2015-09-23 16:51:33 +0300 |
---|---|---|
committer | Henrik Nord <[email protected]> | 2015-10-27 15:06:11 +0100 |
commit | 45251cd60ebad4ef08ffc7cb0797d1fd7a603eea (patch) | |
tree | 547b961e6ed224f4e9baa1d5438d2be9671658e5 /lib/inets/test/httpc_SUITE.erl | |
parent | f4b02cf574552f40ff354261b4c7cf02cb568212 (diff) | |
download | otp-45251cd60ebad4ef08ffc7cb0797d1fd7a603eea.tar.gz otp-45251cd60ebad4ef08ffc7cb0797d1fd7a603eea.tar.bz2 otp-45251cd60ebad4ef08ffc7cb0797d1fd7a603eea.zip |
inets: fix {self, once} for not streamed request
httpc should work properly if streaming option {self, once} is
chosen and the corresponding response does not get streamed.
Diffstat (limited to 'lib/inets/test/httpc_SUITE.erl')
-rw-r--r-- | lib/inets/test/httpc_SUITE.erl | 43 |
1 files changed, 33 insertions, 10 deletions
diff --git a/lib/inets/test/httpc_SUITE.erl b/lib/inets/test/httpc_SUITE.erl index cc0fa5d4d9..989563cdbc 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, + not_streamed_once, stream_large_not_200_or_206, no_content_204, tolerate_missing_CR, @@ -415,7 +416,15 @@ stream_large_not_200_or_206() -> "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}). + {404, _} = not_streamed_test(Request, {stream, self}). +%%------------------------------------------------------------------------- +not_streamed_once() -> + [{doc, "Test not streamed responses with once streaming"}]. +not_streamed_once(Config) when is_list(Config) -> + Request0 = {url(group_name(Config), "/404.html", Config), []}, + {404, _} = not_streamed_test(Request0, {stream, {self, once}}), + Request1 = {url(group_name(Config), "/404_chunked.html", Config), []}, + {404, _} = not_streamed_test(Request1, {stream, {self, once}}). %%------------------------------------------------------------------------- @@ -1125,18 +1134,18 @@ stream_test(Request, To) -> Body = binary_to_list(StreamedBody). -non_streamed_async_test(Request, To) -> - {ok, Response} = +not_streamed_test(Request, To) -> + {ok, {{_,Code,_}, [_ | _], Body}} = httpc:request(get, Request, [], [{body_format, binary}]), {ok, RequestId} = - httpc:request(get, Request, [], [{sync, false}, To]), + httpc:request(get, Request, [], [{body_format, binary}, {sync, false}, To]), - receive - {http, {RequestId, Response}} -> - Response; - {http, Msg} -> - ct:fail(Msg) - end. + receive + {http, {RequestId, {{_, Code, _}, _Headers, Body}}} -> + {Code, binary_to_list(Body)}; + {http, Msg} -> + ct:fail(Msg) + end. url(http, End, Config) -> Port = ?config(port, Config), @@ -1669,6 +1678,11 @@ handle_uri(_,"/307.html",Port,_,Socket,_) -> "Content-Length:" ++ integer_to_list(length(Body)) ++ "\r\n\r\n" ++ Body; +handle_uri(_,"/404.html",_,_,_,_) -> + "HTTP/1.1 404 not found\r\n" ++ + "Content-Length:14\r\n\r\n" ++ + "Page not found"; + handle_uri(_,"/500.html",_,_,_,_) -> "HTTP/1.1 500 Internal Server Error\r\n" ++ "Content-Length:47\r\n\r\n" ++ @@ -1804,6 +1818,15 @@ handle_uri(_,"/once_chunked.html",_,_,Socket,_) -> http_chunk:encode("obar</BODY></HTML>")), http_chunk:encode_last(); +handle_uri(_,"/404_chunked.html",_,_,Socket,_) -> + Head = "HTTP/1.1 404 not found\r\n" ++ + "Transfer-Encoding:Chunked\r\n\r\n", + send(Socket, Head), + send(Socket, http_chunk:encode("<HTML><BODY>Not ")), + send(Socket, + http_chunk:encode("found</BODY></HTML>")), + http_chunk:encode_last(); + handle_uri(_,"/single_chunk.html",_,_,Socket,_) -> Chunk = "HTTP/1.1 200 ok\r\n" ++ "Transfer-Encoding:Chunked\r\n\r\n" ++ |