diff options
author | Tom Burdick <[email protected]> | 2012-11-27 13:34:59 -0600 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2012-12-22 21:20:39 +0100 |
commit | 13c28b8f58dc9f0867184e4e50a5b46e08e4d704 (patch) | |
tree | 7f9503cbc3d48450d7b35549b2809d8ee9928529 /src | |
parent | f7929d323cd448b9fedd4b6799f721eb5550882f (diff) | |
download | cowboy-13c28b8f58dc9f0867184e4e50a5b46e08e4d704.tar.gz cowboy-13c28b8f58dc9f0867184e4e50a5b46e08e4d704.tar.bz2 cowboy-13c28b8f58dc9f0867184e4e50a5b46e08e4d704.zip |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/cowboy_protocol.erl | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/src/cowboy_protocol.erl b/src/cowboy_protocol.erl index 7ab66a9..7344d1f 100644 --- a/src/cowboy_protocol.erl +++ b/src/cowboy_protocol.erl @@ -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. @@ -631,6 +631,17 @@ next_request(Req, State=#state{req_keepalive=Keepalive}, HandlerRes) -> 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, onresponse=OnResponse}) -> |