aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2011-10-24 10:11:09 +0200
committerLoïc Hoguin <[email protected]>2011-10-24 10:11:09 +0200
commitf990109af6f84a5d66c54e52925c55633a0ad859 (patch)
tree8094859250d2e23962650dd3954419f05abc8ca3 /src
parentc589922ebdc7cc6b843c0dbc9ec18a9b7f902586 (diff)
downloadcowboy-f990109af6f84a5d66c54e52925c55633a0ad859.tar.gz
cowboy-f990109af6f84a5d66c54e52925c55633a0ad859.tar.bz2
cowboy-f990109af6f84a5d66c54e52925c55633a0ad859.zip
We don't need to retrieve the Origin header for hybi-7+ websocket drafts
Diffstat (limited to 'src')
-rw-r--r--src/cowboy_http_websocket.erl11
1 files changed, 4 insertions, 7 deletions
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},