0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-15 12:40:25 +00:00

Do not attempt to skip the request body on Connection: close

This commit is contained in:
Loïc Hoguin 2013-01-29 13:34:22 +01:00
parent b2ba4d28f8
commit 8050f2e0fa

View file

@ -522,18 +522,25 @@ resume(State, Env, Tail, Module, Function, Args) ->
next_request(Req, State=#state{req_keepalive=Keepalive, timeout=Timeout}, next_request(Req, State=#state{req_keepalive=Keepalive, timeout=Timeout},
HandlerRes) -> HandlerRes) ->
cowboy_req:ensure_response(Req, 204), cowboy_req:ensure_response(Req, 204),
{BodyRes, [Buffer, Connection]} = case cowboy_req:skip_body(Req) of %% If we are going to close the connection,
{ok, Req2} -> {ok, cowboy_req:get([buffer, connection], Req2)}; %% we do not want to attempt to skip the body.
{error, _} -> {close, [<<>>, close]} case cowboy_req:get(connection, Req) of
end, close ->
%% Flush the resp_sent message before moving on. terminate(State);
receive {cowboy_req, resp_sent} -> ok after 0 -> ok end, _ ->
case {HandlerRes, BodyRes, Connection} of Buffer = case cowboy_req:skip_body(Req) of
{ok, ok, keepalive} -> {ok, Req2} -> cowboy_req:get(buffer, Req2);
?MODULE:parse_request(Buffer, State#state{ _ -> close
req_keepalive=Keepalive + 1, until=until(Timeout)}, 0); end,
_Closed -> %% Flush the resp_sent message before moving on.
terminate(State) 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. end.
%% Only send an error reply if there is no resp_sent message. %% Only send an error reply if there is no resp_sent message.