aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2013-01-29 13:34:22 +0100
committerLoïc Hoguin <[email protected]>2013-01-29 13:34:22 +0100
commit8050f2e0fab45cd623d2044c94350b6b1ea43c71 (patch)
tree7898b75a62295e4daf77c2718d6500bcee096ebe /src
parentb2ba4d28f8962f7c24acf7dfcfb7de936e5f6026 (diff)
downloadcowboy-8050f2e0fab45cd623d2044c94350b6b1ea43c71.tar.gz
cowboy-8050f2e0fab45cd623d2044c94350b6b1ea43c71.tar.bz2
cowboy-8050f2e0fab45cd623d2044c94350b6b1ea43c71.zip
Do not attempt to skip the request body on Connection: close
Diffstat (limited to 'src')
-rw-r--r--src/cowboy_protocol.erl31
1 files changed, 19 insertions, 12 deletions
diff --git a/src/cowboy_protocol.erl b/src/cowboy_protocol.erl
index a0f571b..b479fa9 100644
--- a/src/cowboy_protocol.erl
+++ b/src/cowboy_protocol.erl
@@ -522,18 +522,25 @@ resume(State, Env, Tail, Module, Function, Args) ->
next_request(Req, State=#state{req_keepalive=Keepalive, timeout=Timeout},
HandlerRes) ->
cowboy_req:ensure_response(Req, 204),
- {BodyRes, [Buffer, Connection]} = case cowboy_req:skip_body(Req) of
- {ok, Req2} -> {ok, cowboy_req:get([buffer, connection], Req2)};
- {error, _} -> {close, [<<>>, close]}
- end,
- %% Flush the resp_sent message before moving on.
- receive {cowboy_req, resp_sent} -> ok after 0 -> ok end,
- case {HandlerRes, BodyRes, Connection} of
- {ok, ok, keepalive} ->
- ?MODULE:parse_request(Buffer, State#state{
- req_keepalive=Keepalive + 1, until=until(Timeout)}, 0);
- _Closed ->
- terminate(State)
+ %% If we are going to close the connection,
+ %% we do not want to attempt to skip the body.
+ case cowboy_req:get(connection, Req) of
+ close ->
+ terminate(State);
+ _ ->
+ Buffer = case cowboy_req:skip_body(Req) of
+ {ok, Req2} -> cowboy_req:get(buffer, Req2);
+ _ -> close
+ end,
+ %% Flush the resp_sent message before moving on.
+ receive {cowboy_req, resp_sent} -> ok after 0 -> ok end,
+ if HandlerRes =:= ok, Buffer =/= close ->
+ ?MODULE:parse_request(Buffer,
+ State#state{req_keepalive=Keepalive + 1,
+ until=until(Timeout)}, 0);
+ true ->
+ terminate(State)
+ end
end.
%% Only send an error reply if there is no resp_sent message.