From 9eab26d8353f1546ad8209196c36e42d616f952e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Mon, 2 Sep 2013 19:14:28 +0200 Subject: Add request body support for SPDY And various other improvements following the addition of two tests. New dependency cowlib that will gradually receive most of the parse code from SPDY but also HTTP and its headers. --- test/spdy_SUITE.erl | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/spdy_SUITE.erl b/test/spdy_SUITE.erl index 3cb32ce..6c19792 100644 --- a/test/spdy_SUITE.erl +++ b/test/spdy_SUITE.erl @@ -26,6 +26,8 @@ %% Tests. -export([check_status/1]). +-export([echo_body/1]). +-export([echo_body_multi/1]). %% ct. @@ -34,7 +36,9 @@ all() -> groups() -> [{spdy, [], [ - check_status + check_status, + echo_body, + echo_body_multi ]}]. init_per_suite(Config) -> @@ -82,6 +86,7 @@ init_dispatch(Config) -> {"/static/[...]", cowboy_static, [{directory, ?config(static_dir, Config)}, {mimetypes, [{<<".css">>, [<<"text/css">>]}]}]}, + {"/echo/body", http_echo_body, []}, {"/chunked", http_chunked, []}, {"/", http_handler, []} ]} @@ -120,3 +125,59 @@ check_status(Config) -> {Ret, IsFin, Host, Path} end || {Status, Fin, Host, Path} <- Tests], gun:close(Pid). + +echo_body(Config) -> + {_, Port} = lists:keyfind(port, 1, Config), + {ok, Pid} = gun:open("localhost", Port), + MRef = monitor(process, Pid), + Body = << 0:800000 >>, + StreamRef = gun:post(Pid, "/echo/body", [ + {<<"content-length">>, integer_to_list(byte_size(Body))}, + {<<"content-type">>, "application/octet-stream"} + ], Body), + receive + {'DOWN', MRef, _, _, Reason} -> + error(Reason); + {gun_response, Pid, StreamRef, nofin, << "200", _/bits >>, _} -> + ok + after 1000 -> + error(response_timeout) + end, + receive + {'DOWN', MRef, _, _, Reason2} -> + error({gun_data, Reason2}); + {gun_data, Pid, StreamRef, fin, Body} -> + ok + after 1000 -> + error(data_timeout) + end, + gun:close(Pid). + +echo_body_multi(Config) -> + {_, Port} = lists:keyfind(port, 1, Config), + {ok, Pid} = gun:open("localhost", Port), + MRef = monitor(process, Pid), + BodyChunk = << 0:80000 >>, + StreamRef = gun:post(Pid, "/echo/body", [ + {<<"content-length">>, integer_to_list(byte_size(BodyChunk) * 10)}, + {<<"content-type">>, "application/octet-stream"} + ]), + _ = [gun:data(Pid, StreamRef, nofin, BodyChunk) || _ <- lists:seq(1, 9)], + gun:data(Pid, StreamRef, fin, BodyChunk), + receive + {'DOWN', MRef, _, _, Reason} -> + error(Reason); + {gun_response, Pid, StreamRef, nofin, << "200", _/bits >>, _} -> + ok + after 1000 -> + error(response_timeout) + end, + receive + {'DOWN', MRef, _, _, Reason2} -> + error({gun_data, Reason2}); + {gun_data, Pid, StreamRef, fin, << 0:800000 >>} -> + ok + after 1000 -> + error(data_timeout) + end, + gun:close(Pid). -- cgit v1.2.3