diff options
author | Loïc Hoguin <[email protected]> | 2012-04-29 01:20:24 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2012-04-29 15:22:20 +0200 |
commit | ee8c50c5ab97dcaebc8932d093741fdb496e00f7 (patch) | |
tree | 8e2b4e48361681cad25042ba85a22187ec452154 /src/cowboy_http_protocol.erl | |
parent | 845d306df68f37bb5246b0ce21b2a70456f042c4 (diff) | |
download | cowboy-ee8c50c5ab97dcaebc8932d093741fdb496e00f7.tar.gz cowboy-ee8c50c5ab97dcaebc8932d093741fdb496e00f7.tar.bz2 cowboy-ee8c50c5ab97dcaebc8932d093741fdb496e00f7.zip |
Fix and rework the HTTP test suite
Use a proper HTTP client to run all tests. This client is currently
undocumented and should not be used.
Includes a few fixes:
* Fix a bug in the max_keepalive test
* Fix a bug with max_keepalive handling
* Fix a bug in stream_body/1 where data was lost under some conditions
The tests now run quite faster than before.
All the tests now run twice: once for TCP, once for SSL.
Diffstat (limited to 'src/cowboy_http_protocol.erl')
-rw-r--r-- | src/cowboy_http_protocol.erl | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/src/cowboy_http_protocol.erl b/src/cowboy_http_protocol.erl index 04abfbc..816c825 100644 --- a/src/cowboy_http_protocol.erl +++ b/src/cowboy_http_protocol.erl @@ -121,16 +121,22 @@ request({http_request, Method, {absoluteURI, _Scheme, _Host, _Port, Path}, request({http_request, Method, {abs_path, Path}, Version}, State); request({http_request, Method, {abs_path, AbsPath}, Version}, State=#state{socket=Socket, transport=Transport, + req_keepalive=Keepalive, max_keepalive=MaxKeepalive, urldecode={URLDecFun, URLDecArg}=URLDec}) -> URLDecode = fun(Bin) -> URLDecFun(Bin, URLDecArg) end, {Path, RawPath, Qs} = cowboy_dispatcher:split_path(AbsPath, URLDecode), - ConnAtom = version_to_connection(Version), + ConnAtom = if Keepalive < MaxKeepalive -> version_to_connection(Version); + true -> close + end, parse_header(#http_req{socket=Socket, transport=Transport, connection=ConnAtom, pid=self(), method=Method, version=Version, path=Path, raw_path=RawPath, raw_qs=Qs, urldecode=URLDec}, State); request({http_request, Method, '*', Version}, - State=#state{socket=Socket, transport=Transport, urldecode=URLDec}) -> - ConnAtom = version_to_connection(Version), + State=#state{socket=Socket, transport=Transport, + req_keepalive=Keepalive, max_keepalive=MaxKeepalive, urldecode=URLDec}) -> + ConnAtom = if Keepalive < MaxKeepalive -> version_to_connection(Version); + true -> close + end, parse_header(#http_req{socket=Socket, transport=Transport, connection=ConnAtom, pid=self(), method=Method, version=Version, path='*', raw_path= <<"*">>, raw_qs= <<>>, urldecode=URLDec}, State); @@ -186,7 +192,9 @@ header({http_header, _I, 'Host', _R, RawHost}, Req=#http_req{ header({http_header, _I, 'Host', _R, _V}, Req, State) -> parse_header(Req, State); header({http_header, _I, 'Connection', _R, Connection}, - Req=#http_req{headers=Headers}, State) -> + Req=#http_req{headers=Headers}, State=#state{ + req_keepalive=Keepalive, max_keepalive=MaxKeepalive}) + when Keepalive < MaxKeepalive -> Req2 = Req#http_req{headers=[{'Connection', Connection}|Headers]}, {ConnTokens, Req3} = cowboy_http_req:parse_header('Connection', Req2), @@ -376,15 +384,14 @@ terminate_request(HandlerState, Req, State) -> next_request(Req, State, HandlerRes). -spec next_request(#http_req{}, #state{}, any()) -> ok. -next_request(Req=#http_req{connection=Conn}, - State=#state{req_keepalive=Keepalive, max_keepalive=MaxKeepalive}, - HandlerRes) -> +next_request(Req=#http_req{connection=Conn}, State=#state{ + req_keepalive=Keepalive}, HandlerRes) -> RespRes = ensure_response(Req), {BodyRes, Buffer} = ensure_body_processed(Req), %% Flush the resp_sent message before moving on. receive {cowboy_http_req, resp_sent} -> ok after 0 -> ok end, case {HandlerRes, BodyRes, RespRes, Conn} of - {ok, ok, ok, keepalive} when Keepalive < MaxKeepalive -> + {ok, ok, ok, keepalive} -> ?MODULE:parse_request(State#state{ buffer=Buffer, req_empty_lines=0, req_keepalive=Keepalive + 1}); |