From f990109af6f84a5d66c54e52925c55633a0ad859 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Mon, 24 Oct 2011 10:11:09 +0200 Subject: We don't need to retrieve the Origin header for hybi-7+ websocket drafts --- src/cowboy_http_websocket.erl | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/cowboy_http_websocket.erl b/src/cowboy_http_websocket.erl index 81cd7cd..1111b96 100644 --- a/src/cowboy_http_websocket.erl +++ b/src/cowboy_http_websocket.erl @@ -86,6 +86,7 @@ websocket_upgrade(State, Req) -> websocket_upgrade(Version, State, Req4). %% @todo Handle the Sec-Websocket-Protocol header. +%% @todo Reply a proper error, don't die, if a required header is undefined. -spec websocket_upgrade(undefined | <<_:8>>, #state{}, #http_req{}) -> {ok, #state{}, #http_req{}}. %% No version given. Assuming hixie-76 draft. @@ -94,7 +95,6 @@ websocket_upgrade(State, Req) -> %% third part of the challenge key, because proxies will wait for %% a reply before sending it. Therefore we calculate the challenge %% key only in websocket_handshake/3. -%% @todo Check Origin? websocket_upgrade(undefined, State, Req) -> {Origin, Req2} = cowboy_http_req:header(<<"Origin">>, Req), {Key1, Req3} = cowboy_http_req:header(<<"Sec-Websocket-Key1">>, Req2), @@ -104,15 +104,12 @@ websocket_upgrade(undefined, State, Req) -> {ok, State#state{version=0, origin=Origin, challenge={Key1, Key2}, eop=EOP}, Req4}; %% Versions 7 and 8. Implementation follows the hybi 7 through 10 drafts. -%% @todo We don't need Origin? websocket_upgrade(<< Version >>, State, Req) when Version =:= $7; Version =:= $8 -> - {Origin, Req2} = cowboy_http_req:header(<<"Sec-Websocket-Origin">>, Req), - {Key, Req3} = cowboy_http_req:header(<<"Sec-Websocket-Key">>, Req2), - false = lists:member(undefined, [Origin, Key]), + {Key, Req2} = cowboy_http_req:header(<<"Sec-Websocket-Key">>, Req), + false = Key =:= undefined, Challenge = hybi_challenge(Key), - {ok, State#state{version=Version - $0, origin=Origin, - challenge=Challenge}, Req3}. + {ok, State#state{version=Version - $0, challenge=Challenge}, Req2}. -spec handler_init(#state{}, #http_req{}) -> ok | none(). handler_init(State=#state{handler=Handler, opts=Opts}, -- cgit v1.2.3