Skip to content

Commit

Permalink
Avoid a duplicate HTTP reply in cowboy_websocket:upgrade_error/1
Browse files Browse the repository at this point in the history
Do this by checking whether we received the resp_sent message.
  • Loading branch information
essen committed Sep 15, 2012
1 parent 35ebe0b commit cd54214
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/cowboy_websocket.erl
Expand Up @@ -140,9 +140,12 @@ handler_init(State=#state{transport=Transport, handler=Handler, opts=Opts},

-spec upgrade_error(cowboy_req:req()) -> closed.
upgrade_error(Req) ->
{ok, _Req2} = cowboy_req:reply(400, [], [],
Req#http_req{resp_state=waiting}),
closed.
receive
{cowboy_req, resp_sent} -> closed
after 0 ->
_ = cowboy_req:reply(400, [], [], Req),
closed
end.

%% @see cowboy_protocol:ensure_response/1
-spec upgrade_denied(cowboy_req:req()) -> closed.
Expand Down

0 comments on commit cd54214

Please sign in to comment.