aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2011-09-13 23:41:34 +0200
committerLoïc Hoguin <[email protected]>2011-09-13 23:41:34 +0200
commitb669b1b5a39de6acfa6eb051e53c31eeecc8733e (patch)
tree9a45b3152a1cd264e8f7246e5398c07a2d4b8009
parent961526d70406d26b1d172c2cce72cae2b593f72a (diff)
downloadcowboy-b669b1b5a39de6acfa6eb051e53c31eeecc8733e.tar.gz
cowboy-b669b1b5a39de6acfa6eb051e53c31eeecc8733e.tar.bz2
cowboy-b669b1b5a39de6acfa6eb051e53c31eeecc8733e.zip
Reset the max number of empty lines between keepalive requests
Fixes issue #47.
-rw-r--r--src/cowboy_http_protocol.erl3
-rw-r--r--test/http_SUITE.erl22
2 files changed, 22 insertions, 3 deletions
diff --git a/src/cowboy_http_protocol.erl b/src/cowboy_http_protocol.erl
index 9923591..35a0471 100644
--- a/src/cowboy_http_protocol.erl
+++ b/src/cowboy_http_protocol.erl
@@ -246,7 +246,8 @@ next_request(HandlerState, Req=#http_req{buffer=Buffer}, State) ->
RespRes = ensure_response(Req, State),
case {HandlerRes, BodyRes, RespRes, State#state.connection} of
{ok, ok, ok, keepalive} ->
- ?MODULE:parse_request(State#state{buffer=Buffer});
+ ?MODULE:parse_request(State#state{
+ buffer=Buffer, req_empty_lines=0});
_Closed ->
terminate(State)
end.
diff --git a/test/http_SUITE.erl b/test/http_SUITE.erl
index 2db3f4e..d4d99e8 100644
--- a/test/http_SUITE.erl
+++ b/test/http_SUITE.erl
@@ -19,7 +19,7 @@
-export([all/0, groups/0, init_per_suite/1, end_per_suite/1,
init_per_group/2, end_per_group/2]). %% ct.
-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.
%% ct.
@@ -30,7 +30,7 @@ all() ->
groups() ->
BaseTests = [http_200, http_404],
[{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}].
init_per_suite(Config) ->
@@ -113,6 +113,24 @@ headers_huge(Config) ->
{_Packet, 200} = raw_req(["GET / HTTP/1.0\r\nHost: localhost\r\n"
"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) ->
Cat = os:find_executable("cat"),
Nc = os:find_executable("nc"),