0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-14 20:30:23 +00:00

use the original request when available for error_terminate

this change makes sure that once a request has been created
the error_terminate/3 function uses the original request instead
of making a new empty one with undefined values making the request
attributes easier to look at in many error cases

Conflicts:
	src/cowboy_protocol.erl
This commit is contained in:
Tom Burdick 2012-11-27 13:34:59 -06:00 committed by Loïc Hoguin
parent f7929d323c
commit 13c28b8f58

View file

@ -465,11 +465,11 @@ dispatch(Req, State=#state{dispatch=Dispatch}, Host, Path) ->
Req2 = cowboy_req:set_bindings(HostInfo, PathInfo, Bindings, Req),
handler_init(Req2, State, Handler, Opts);
{error, notfound, host} ->
error_terminate(400, State);
error_terminate(400, Req, State);
{error, badrequest, path} ->
error_terminate(400, State);
error_terminate(400, Req, State);
{error, notfound, path} ->
error_terminate(404, State)
error_terminate(404, Req, State)
end.
-spec handler_init(cowboy_req:req(), #state{}, module(), any()) -> ok.
@ -497,7 +497,7 @@ handler_init(Req, State=#state{transport=Transport}, Handler, Opts) ->
{upgrade, protocol, Module, Req2, Opts2} ->
upgrade_protocol(Req2, State, Handler, Opts2, Module)
catch Class:Reason ->
error_terminate(500, State),
error_terminate(500, Req, State),
error_logger:error_msg(
"** Cowboy handler ~p terminating in ~p/~p~n"
" for the reason ~p:~p~n"
@ -532,7 +532,7 @@ handler_handle(Req, State, Handler, HandlerState) ->
[Handler, handle, 2, Class, Reason, HandlerState,
cowboy_req:to_list(Req), erlang:get_stacktrace()]),
handler_terminate(Req, Handler, HandlerState),
error_terminate(500, State)
error_terminate(500, Req, State)
end.
%% We don't listen for Transport closes because that would force us
@ -590,7 +590,7 @@ handler_call(Req, State, Handler, HandlerState, Message) ->
[Handler, info, 3, Class, Reason, HandlerState,
cowboy_req:to_list(Req), erlang:get_stacktrace()]),
handler_terminate(Req, Handler, HandlerState),
error_terminate(500, State)
error_terminate(500, Req, State)
end.
-spec handler_terminate(cowboy_req:req(), module(), any()) -> ok.
@ -630,6 +630,17 @@ next_request(Req, State=#state{req_keepalive=Keepalive}, HandlerRes) ->
terminate(State)
end.
%% Only send an error reply if there is no resp_sent message.
-spec error_terminate(cowboy_http:status(), cowboy_req:req(), #state{}) -> ok.
error_terminate(Code, Req, State) ->
receive
{cowboy_req, resp_sent} -> ok
after 0 ->
_ = cowboy_req:reply(Code, Req),
ok
end,
terminate(State).
%% Only send an error reply if there is no resp_sent message.
-spec error_terminate(cowboy_http:status(), #state{}) -> ok.
error_terminate(Code, State=#state{socket=Socket, transport=Transport,