diff options
author | Loïc Hoguin <[email protected]> | 2011-12-06 12:54:09 +0100 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2011-12-06 12:54:09 +0100 |
commit | a12a910341dd22bd27096b50edf3d9820bc90384 (patch) | |
tree | c2bac5bab3952d2bad51f581811f8a30521953e5 /src | |
parent | 3649b0ee0dd5ea9d64cc64fb0c16a20db21322f4 (diff) | |
download | cowboy-a12a910341dd22bd27096b50edf3d9820bc90384.tar.gz cowboy-a12a910341dd22bd27096b50edf3d9820bc90384.tar.bz2 cowboy-a12a910341dd22bd27096b50edf3d9820bc90384.zip |
Fix a crash in websocket_handshake/3 with hixie-76
Happened when an error occurred while trying to read the body to
get the key. Also fixes all the dialyzer warnings in cowboy_http_websocket.
Diffstat (limited to 'src')
-rw-r--r-- | src/cowboy_http_websocket.erl | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/cowboy_http_websocket.erl b/src/cowboy_http_websocket.erl index 08a0c90..d40e7af 100644 --- a/src/cowboy_http_websocket.erl +++ b/src/cowboy_http_websocket.erl @@ -178,11 +178,15 @@ websocket_handshake(State=#state{version=0, origin=Origin, %% 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. - {ok, Key3, Req3} = cowboy_http_req:body(8, Req2), - Challenge = hixie76_challenge(Key1, Key2, Key3), - Transport:send(Socket, Challenge), - handler_before_loop(State#state{messages=Transport:messages()}, - Req3, HandlerState, <<>>); + case cowboy_http_req:body(8, Req2) of + {ok, Key3, Req3} -> + Challenge = hixie76_challenge(Key1, Key2, Key3), + Transport:send(Socket, Challenge), + handler_before_loop(State#state{messages=Transport:messages()}, + Req3, HandlerState, <<>>); + _Any -> + ok %% If an error happened reading the body, stop there. + end; websocket_handshake(State=#state{challenge=Challenge}, Req=#http_req{transport=Transport}, HandlerState) -> {ok, Req2} = cowboy_http_req:upgrade_reply( |