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

ct: Add a test for requests pipelining.

This commit is contained in:
Loïc Hoguin 2011-04-10 02:43:30 +02:00
parent f05953516b
commit 0ef66b78f7

View file

@ -18,7 +18,7 @@
-export([all/0, groups/0, init_per_suite/1, end_per_suite/1,
init_per_group/2, end_per_group/2]). %% ct.
-export([raw/1]). %% http.
-export([pipeline/1, raw/1]). %% http.
-export([http_200/1, http_404/1]). %% http and https.
%% ct.
@ -28,7 +28,7 @@ all() ->
groups() ->
BaseTests = [http_200, http_404],
[{http, [], [raw] ++ BaseTests},
[{http, [], [pipeline, raw] ++ BaseTests},
{https, [], BaseTests}].
init_per_suite(Config) ->
@ -84,6 +84,36 @@ init_https_dispatch() ->
%% http.
pipeline(Config) ->
{port, Port} = lists:keyfind(port, 1, Config),
{ok, Socket} = gen_tcp:connect("localhost", Port,
[binary, {active, false}, {packet, raw}]),
ok = gen_tcp:send(Socket,
"GET / HTTP/1.1\r\nHost: localhost\r\nConnection: keep-alive\r\n\r\n"
"GET / HTTP/1.1\r\nHost: localhost\r\nConnection: keep-alive\r\n\r\n"
"GET / HTTP/1.1\r\nHost: localhost\r\nConnection: keep-alive\r\n\r\n"
"GET / HTTP/1.1\r\nHost: localhost\r\nConnection: keep-alive\r\n\r\n"
"GET / HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n"),
Data = pipeline_recv(Socket, <<>>),
Reqs = binary:split(Data, << "\r\n\r\nhttp_handler" >>, [global, trim]),
5 = length(Reqs),
pipeline_check(Reqs).
pipeline_check([]) ->
ok;
pipeline_check([Req|Tail]) ->
<< "HTTP/1.1 200", _Rest/bits >> = Req,
pipeline_check(Tail).
pipeline_recv(Socket, SoFar) ->
case gen_tcp:recv(Socket, 0, 6000) of
{ok, Data} ->
pipeline_recv(Socket, << SoFar/binary, Data/binary >>);
{error, closed} ->
ok = gen_tcp:close(Socket),
SoFar
end.
raw_req(Packet, Config) ->
{port, Port} = lists:keyfind(port, 1, Config),
{ok, Socket} = gen_tcp:connect("localhost", Port,