From 4b93c2d19a10e5d9cee207038103bb83f1ab9436 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Mon, 23 Jan 2012 21:57:54 +0100 Subject: Fix a case where request body wouldn't get cleaned up on keepalive The body was still in the buffer that's being used for the next request and was thus used as a request, causing errors. --- src/cowboy_http_protocol.erl | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/cowboy_http_protocol.erl b/src/cowboy_http_protocol.erl index a714111..baee081 100644 --- a/src/cowboy_http_protocol.erl +++ b/src/cowboy_http_protocol.erl @@ -356,11 +356,11 @@ terminate_request(HandlerState, Req, State) -> next_request(Req, State, HandlerRes). -spec next_request(#http_req{}, #state{}, any()) -> ok | none(). -next_request(Req=#http_req{connection=Conn, buffer=Buffer}, +next_request(Req=#http_req{connection=Conn}, State=#state{req_keepalive=Keepalive, max_keepalive=MaxKeepalive}, HandlerRes) -> RespRes = ensure_response(Req), - BodyRes = ensure_body_processed(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 @@ -372,14 +372,14 @@ next_request(Req=#http_req{connection=Conn, buffer=Buffer}, terminate(State) end. --spec ensure_body_processed(#http_req{}) -> ok | close. -ensure_body_processed(#http_req{body_state=done}) -> - ok; +-spec ensure_body_processed(#http_req{}) -> {ok | close, binary()}. +ensure_body_processed(#http_req{body_state=done, buffer=Buffer}) -> + {ok, Buffer}; ensure_body_processed(Req=#http_req{body_state=waiting}) -> case cowboy_http_req:body(Req) of - {error, badarg} -> ok; %% No body. - {error, _Reason} -> close; - _Any -> ok + {error, badarg} -> {ok, Req#http_req.buffer}; %% No body. + {error, _Reason} -> {close, <<>>}; + {ok, _, Req2} -> {ok, Req2#http_req.buffer} end; ensure_body_processed(Req=#http_req{body_state={multipart, _, _}}) -> {ok, Req2} = cowboy_http_req:multipart_skip(Req), -- cgit v1.2.3