mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-14 12:20:24 +00:00
Reset the max number of empty lines between keepalive requests
Fixes issue #47.
This commit is contained in:
parent
961526d704
commit
b669b1b5a3
2 changed files with 22 additions and 3 deletions
|
@ -246,7 +246,8 @@ next_request(HandlerState, Req=#http_req{buffer=Buffer}, State) ->
|
||||||
RespRes = ensure_response(Req, State),
|
RespRes = ensure_response(Req, State),
|
||||||
case {HandlerRes, BodyRes, RespRes, State#state.connection} of
|
case {HandlerRes, BodyRes, RespRes, State#state.connection} of
|
||||||
{ok, ok, ok, keepalive} ->
|
{ok, ok, ok, keepalive} ->
|
||||||
?MODULE:parse_request(State#state{buffer=Buffer});
|
?MODULE:parse_request(State#state{
|
||||||
|
buffer=Buffer, req_empty_lines=0});
|
||||||
_Closed ->
|
_Closed ->
|
||||||
terminate(State)
|
terminate(State)
|
||||||
end.
|
end.
|
||||||
|
|
|
@ -19,7 +19,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([chunked_response/1, headers_dupe/1, headers_huge/1,
|
-export([chunked_response/1, headers_dupe/1, headers_huge/1,
|
||||||
nc_rand/1, pipeline/1, raw/1, ws0/1, ws8/1]). %% http.
|
keepalive_nl/1, nc_rand/1, pipeline/1, raw/1, ws0/1, ws8/1]). %% http.
|
||||||
-export([http_200/1, http_404/1]). %% http and https.
|
-export([http_200/1, http_404/1]). %% http and https.
|
||||||
|
|
||||||
%% ct.
|
%% ct.
|
||||||
|
@ -30,7 +30,7 @@ all() ->
|
||||||
groups() ->
|
groups() ->
|
||||||
BaseTests = [http_200, http_404],
|
BaseTests = [http_200, http_404],
|
||||||
[{http, [], [chunked_response, headers_dupe, headers_huge,
|
[{http, [], [chunked_response, headers_dupe, headers_huge,
|
||||||
nc_rand, pipeline, raw, ws0, ws8] ++ BaseTests},
|
keepalive_nl, nc_rand, pipeline, raw, ws0, ws8] ++ BaseTests},
|
||||||
{https, [], BaseTests}].
|
{https, [], BaseTests}].
|
||||||
|
|
||||||
init_per_suite(Config) ->
|
init_per_suite(Config) ->
|
||||||
|
@ -113,6 +113,24 @@ headers_huge(Config) ->
|
||||||
{_Packet, 200} = raw_req(["GET / HTTP/1.0\r\nHost: localhost\r\n"
|
{_Packet, 200} = raw_req(["GET / HTTP/1.0\r\nHost: localhost\r\n"
|
||||||
"Set-Cookie: ", Cookie, "\r\n\r\n"], Config).
|
"Set-Cookie: ", Cookie, "\r\n\r\n"], Config).
|
||||||
|
|
||||||
|
keepalive_nl(Config) ->
|
||||||
|
{port, Port} = lists:keyfind(port, 1, Config),
|
||||||
|
{ok, Socket} = gen_tcp:connect("localhost", Port,
|
||||||
|
[binary, {active, false}, {packet, raw}]),
|
||||||
|
ok = keepalive_nl_loop(Socket, 100),
|
||||||
|
ok = gen_tcp:close(Socket).
|
||||||
|
|
||||||
|
keepalive_nl_loop(_Socket, 0) ->
|
||||||
|
ok;
|
||||||
|
keepalive_nl_loop(Socket, N) ->
|
||||||
|
ok = gen_tcp:send(Socket, "GET / HTTP/1.1\r\n"
|
||||||
|
"Host: localhost\r\nConnection: keep-alive\r\n\r\n"),
|
||||||
|
{ok, Data} = gen_tcp:recv(Socket, 0, 6000),
|
||||||
|
{0, 12} = binary:match(Data, <<"HTTP/1.1 200">>),
|
||||||
|
nomatch = binary:match(Data, <<"Connection: close">>),
|
||||||
|
ok = gen_tcp:send(Socket, "\r\n"), %% extra nl
|
||||||
|
keepalive_nl_loop(Socket, N - 1).
|
||||||
|
|
||||||
nc_rand(Config) ->
|
nc_rand(Config) ->
|
||||||
Cat = os:find_executable("cat"),
|
Cat = os:find_executable("cat"),
|
||||||
Nc = os:find_executable("nc"),
|
Nc = os:find_executable("nc"),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue