0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-16 05:00:24 +00:00

Fix handler crashes handling

We try to send a 500 error only if we didn't send the response
headers yet. If they were, then we have no way to be sure the
response was fully sent, nor should we assume anything about
how this will be handled client-side, so we do nothing more
and in both cases close the connection.
This commit is contained in:
Loïc Hoguin 2012-01-02 09:41:30 +01:00
parent ba87aa4193
commit fd211d3c03
4 changed files with 31 additions and 11 deletions

View file

@ -169,6 +169,8 @@ websocket_handshake(State=#state{version=0, origin=Origin,
{<<"Sec-Websocket-Location">>, Location},
{<<"Sec-Websocket-Origin">>, Origin}],
Req#http_req{resp_state=waiting}),
%% Flush the resp_sent message before moving on.
receive {cowboy_http_req, resp_sent} -> ok after 0 -> ok end,
%% We replied with a proper response. Proxies should be happy enough,
%% we can now read the 8 last bytes of the challenge keys and send
%% the challenge response directly to the socket.
@ -188,6 +190,8 @@ websocket_handshake(State=#state{challenge=Challenge},
[{<<"Upgrade">>, <<"websocket">>},
{<<"Sec-Websocket-Accept">>, Challenge}],
Req#http_req{resp_state=waiting}),
%% Flush the resp_sent message before moving on.
receive {cowboy_http_req, resp_sent} -> ok after 0 -> ok end,
handler_before_loop(State#state{messages=Transport:messages()},
Req2, HandlerState, <<>>).