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:
parent
f05953516b
commit
0ef66b78f7
1 changed files with 32 additions and 2 deletions
|
@ -18,7 +18,7 @@
|
||||||
|
|
||||||
-export([all/0, groups/0, init_per_suite/1, end_per_suite/1,
|
-export([all/0, groups/0, init_per_suite/1, end_per_suite/1,
|
||||||
init_per_group/2, end_per_group/2]). %% ct.
|
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.
|
-export([http_200/1, http_404/1]). %% http and https.
|
||||||
|
|
||||||
%% ct.
|
%% ct.
|
||||||
|
@ -28,7 +28,7 @@ all() ->
|
||||||
|
|
||||||
groups() ->
|
groups() ->
|
||||||
BaseTests = [http_200, http_404],
|
BaseTests = [http_200, http_404],
|
||||||
[{http, [], [raw] ++ BaseTests},
|
[{http, [], [pipeline, raw] ++ BaseTests},
|
||||||
{https, [], BaseTests}].
|
{https, [], BaseTests}].
|
||||||
|
|
||||||
init_per_suite(Config) ->
|
init_per_suite(Config) ->
|
||||||
|
@ -84,6 +84,36 @@ init_https_dispatch() ->
|
||||||
|
|
||||||
%% http.
|
%% 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) ->
|
raw_req(Packet, Config) ->
|
||||||
{port, Port} = lists:keyfind(port, 1, Config),
|
{port, Port} = lists:keyfind(port, 1, Config),
|
||||||
{ok, Socket} = gen_tcp:connect("localhost", Port,
|
{ok, Socket} = gen_tcp:connect("localhost", Port,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue