diff options
author | Loïc Hoguin <[email protected]> | 2012-01-23 21:57:54 +0100 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2012-01-23 21:57:54 +0100 |
commit | 4b93c2d19a10e5d9cee207038103bb83f1ab9436 (patch) | |
tree | e75f91d2d984061958492e7655d183d8bdb19fe6 /src/cowboy_http_protocol.erl | |
parent | dd08a905685cd2f40f9145bc2697434102726d4e (diff) | |
download | cowboy-4b93c2d19a10e5d9cee207038103bb83f1ab9436.tar.gz cowboy-4b93c2d19a10e5d9cee207038103bb83f1ab9436.tar.bz2 cowboy-4b93c2d19a10e5d9cee207038103bb83f1ab9436.zip |
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.
Diffstat (limited to 'src/cowboy_http_protocol.erl')
-rw-r--r-- | src/cowboy_http_protocol.erl | 16 |
1 files changed, 8 insertions, 8 deletions
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), |