0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-16 05:00:24 +00:00

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.
This commit is contained in:
Loïc Hoguin 2013-09-02 19:14:28 +02:00
parent d68b3de9d9
commit 9eab26d835
4 changed files with 186 additions and 425 deletions

View file

@ -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).