aboutsummaryrefslogtreecommitdiffstats
path: root/src/cowboy_rest.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2014-07-12 12:09:43 +0200
committerLoïc Hoguin <[email protected]>2014-07-12 12:09:43 +0200
commit97a3108576c6a9d64c03e1455654dba88367992a (patch)
treec9701a8ba567e777509e0fd3508ed6f0bc6b5ea0 /src/cowboy_rest.erl
parent20f598f3736cdaab8fd0e9de09f16d18d1dc97f8 (diff)
downloadcowboy-97a3108576c6a9d64c03e1455654dba88367992a.tar.gz
cowboy-97a3108576c6a9d64c03e1455654dba88367992a.tar.bz2
cowboy-97a3108576c6a9d64c03e1455654dba88367992a.zip
Reply with 400 on header parsing crash
This is a first step to improve the HTTP status codes returned by Cowboy on crashes. We will tweak it over time. Also fixes a small bug where two replies may have been sent when using loop handlers under rare conditions.
Diffstat (limited to 'src/cowboy_rest.erl')
-rw-r--r--src/cowboy_rest.erl10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/cowboy_rest.erl b/src/cowboy_rest.erl
index fd1588a..f779612 100644
--- a/src/cowboy_rest.erl
+++ b/src/cowboy_rest.erl
@@ -66,11 +66,12 @@ upgrade(Req, Env, Handler, HandlerOpts) ->
service_available(Req2, #state{env=Env, method=Method,
handler=Handler, handler_state=HandlerState})
catch Class:Reason ->
- cowboy_req:maybe_reply(500, Req),
+ Stacktrace = erlang:get_stacktrace(),
+ cowboy_req:maybe_reply(Stacktrace, Req),
erlang:Class([
{reason, Reason},
{mfa, {Handler, rest_init, 2}},
- {stacktrace, erlang:get_stacktrace()},
+ {stacktrace, Stacktrace},
{req, cowboy_req:to_list(Req)},
{opts, HandlerOpts}
])
@@ -999,11 +1000,12 @@ terminate(Req, State=#state{env=Env}) ->
error_terminate(Req, State=#state{handler=Handler, handler_state=HandlerState},
Class, Reason, Callback) ->
rest_terminate(Req, State),
- cowboy_req:maybe_reply(500, Req),
+ Stacktrace = erlang:get_stacktrace(),
+ cowboy_req:maybe_reply(Stacktrace, Req),
erlang:Class([
{reason, Reason},
{mfa, {Handler, Callback, 2}},
- {stacktrace, erlang:get_stacktrace()},
+ {stacktrace, Stacktrace},
{req, cowboy_req:to_list(Req)},
{state, HandlerState}
]).