aboutsummaryrefslogtreecommitdiffstats
path: root/src/cowboy_websocket.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_websocket.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_websocket.erl')
-rw-r--r--src/cowboy_websocket.erl13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/cowboy_websocket.erl b/src/cowboy_websocket.erl
index 6c41137..d13441d 100644
--- a/src/cowboy_websocket.erl
+++ b/src/cowboy_websocket.erl
@@ -71,8 +71,12 @@ upgrade(Req, Env, Handler, HandlerOpts) ->
{ok, State2, Req2} ->
handler_init(State2, Req2, HandlerOpts)
catch _:_ ->
- cowboy_req:maybe_reply(400, Req),
- exit(normal)
+ receive
+ {cowboy_req, resp_sent} -> ok
+ after 0 ->
+ cowboy_req:reply(400, Req),
+ exit(normal)
+ end
end.
-spec websocket_upgrade(#state{}, Req)
@@ -144,11 +148,12 @@ handler_init(State=#state{env=Env, transport=Transport,
cowboy_req:ensure_response(Req2, 400),
{ok, Req2, [{result, closed}|Env]}
catch Class:Reason ->
- cowboy_req:maybe_reply(400, Req),
+ Stacktrace = erlang:get_stacktrace(),
+ cowboy_req:maybe_reply(Stacktrace, Req),
erlang:Class([
{reason, Reason},
{mfa, {Handler, websocket_init, 3}},
- {stacktrace, erlang:get_stacktrace()},
+ {stacktrace, Stacktrace},
{req, cowboy_req:to_list(Req)},
{opts, HandlerOpts}
])