aboutsummaryrefslogtreecommitdiffstats
path: root/src/cowboy_http_websocket.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2011-12-19 09:44:24 +0100
committerLoïc Hoguin <[email protected]>2011-12-19 09:44:47 +0100
commitf390dbd60671fd49bd99137f539794b1fbe1c718 (patch)
treedc38e8f6d9697565cff720e43c4952b6f78d6cd0 /src/cowboy_http_websocket.erl
parentf9bd5d1061813be1405977af57390ca7af40e39e (diff)
downloadcowboy-f390dbd60671fd49bd99137f539794b1fbe1c718.tar.gz
cowboy-f390dbd60671fd49bd99137f539794b1fbe1c718.tar.bz2
cowboy-f390dbd60671fd49bd99137f539794b1fbe1c718.zip
Add meta/2 and meta/3 to cowboy_http_req to save useful protocol information
* cowboy_http_protocol now defines 'websocket_version' as metadata. * cowboy_http_rest now defines 'media_type', 'language', 'charset' as metadata.
Diffstat (limited to 'src/cowboy_http_websocket.erl')
-rw-r--r--src/cowboy_http_websocket.erl13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/cowboy_http_websocket.erl b/src/cowboy_http_websocket.erl
index 20060e6..dd1550e 100644
--- a/src/cowboy_http_websocket.erl
+++ b/src/cowboy_http_websocket.erl
@@ -30,9 +30,9 @@
%% <li>Firefox 6</li>
%% </ul>
%%
-%% Version 8 is supported by the following browsers:
+%% Version 8+ is supported by the following browsers:
%% <ul>
-%% <li>Firefox 7</li>
+%% <li>Firefox 7+</li>
%% <li>Chrome 14+</li>
%% </ul>
-module(cowboy_http_websocket).
@@ -95,23 +95,24 @@ 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.
-websocket_upgrade(undefined, State, Req) ->
+websocket_upgrade(undefined, State, Req=#http_req{meta=Meta}) ->
{Origin, Req2} = cowboy_http_req:header(<<"Origin">>, Req),
{Key1, Req3} = cowboy_http_req:header(<<"Sec-Websocket-Key1">>, Req2),
{Key2, Req4} = cowboy_http_req:header(<<"Sec-Websocket-Key2">>, Req3),
false = lists:member(undefined, [Origin, Key1, Key2]),
EOP = binary:compile_pattern(<< 255 >>),
{ok, State#state{version=0, origin=Origin, challenge={Key1, Key2},
- eop=EOP}, Req4};
+ eop=EOP}, Req4#http_req{meta=[{websocket_version, 0}|Meta]}};
%% Versions 7 and 8. Implementation follows the hybi 7 through 17 drafts.
-websocket_upgrade(Version, State, Req)
+websocket_upgrade(Version, State, Req=#http_req{meta=Meta})
when Version =:= <<"7">>; Version =:= <<"8">>;
Version =:= <<"13">> ->
{Key, Req2} = cowboy_http_req:header(<<"Sec-Websocket-Key">>, Req),
false = Key =:= undefined,
Challenge = hybi_challenge(Key),
IntVersion = list_to_integer(binary_to_list(Version)),
- {ok, State#state{version=IntVersion, challenge=Challenge}, Req2}.
+ {ok, State#state{version=IntVersion, challenge=Challenge},
+ Req2#http_req{meta=[{websocket_version, IntVersion}|Meta]}}.
-spec handler_init(#state{}, #http_req{}) -> closed | none().
handler_init(State=#state{handler=Handler, opts=Opts},