aboutsummaryrefslogtreecommitdiffstats
path: root/src/cowboy_websocket.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2012-09-21 09:18:56 +0200
committerLoïc Hoguin <[email protected]>2012-09-21 09:18:56 +0200
commit34021666cbf626e979ea136664b1f8beca893d6f (patch)
treec5c56ca56b6540c42f84278221b442096edf61b0 /src/cowboy_websocket.erl
parent8497c8bbcdcfd8754c500e65557ee09d9bd1bed0 (diff)
downloadcowboy-34021666cbf626e979ea136664b1f8beca893d6f.tar.gz
cowboy-34021666cbf626e979ea136664b1f8beca893d6f.tar.bz2
cowboy-34021666cbf626e979ea136664b1f8beca893d6f.zip
Don't use decode_packet/3 for parsing the headers
Header names are now binaries. Since header names are case insensitive they are all converted to lowercase. For example: <<"content-length">>. The max_line_length option was removed. Three new options have been added instead: * max_request_line_length (defaults to 4096) * max_header_name_length (defaults to 64) * max_header_value_length (defaults to 4096)
Diffstat (limited to 'src/cowboy_websocket.erl')
-rw-r--r--src/cowboy_websocket.erl15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/cowboy_websocket.erl b/src/cowboy_websocket.erl
index a6f2be3..dcd3008 100644
--- a/src/cowboy_websocket.erl
+++ b/src/cowboy_websocket.erl
@@ -72,11 +72,12 @@ upgrade(ListenerPid, Handler, Opts, Req) ->
-> {ok, #state{}, Req} when Req::cowboy_req:req().
websocket_upgrade(State, Req) ->
{ok, ConnTokens, Req2}
- = cowboy_req:parse_header('Connection', Req),
+ = cowboy_req:parse_header(<<"connection">>, Req),
true = lists:member(<<"upgrade">>, ConnTokens),
%% @todo Should probably send a 426 if the Upgrade header is missing.
- {ok, [<<"websocket">>], Req3} = cowboy_req:parse_header('Upgrade', Req2),
- {Version, Req4} = cowboy_req:header(<<"Sec-Websocket-Version">>, Req3),
+ {ok, [<<"websocket">>], Req3}
+ = cowboy_req:parse_header(<<"upgrade">>, Req2),
+ {Version, Req4} = cowboy_req:header(<<"sec-websocket-version">>, Req3),
websocket_upgrade(Version, State, Req4).
%% @todo Handle the Sec-Websocket-Protocol header.
@@ -90,9 +91,9 @@ websocket_upgrade(State, Req) ->
%% a reply before sending it. Therefore we calculate the challenge
%% key only in websocket_handshake/3.
websocket_upgrade(undefined, State, Req) ->
- {Origin, Req2} = cowboy_req:header(<<"Origin">>, Req),
- {Key1, Req3} = cowboy_req:header(<<"Sec-Websocket-Key1">>, Req2),
- {Key2, Req4} = cowboy_req:header(<<"Sec-Websocket-Key2">>, Req3),
+ {Origin, Req2} = cowboy_req:header(<<"origin">>, Req),
+ {Key1, Req3} = cowboy_req:header(<<"sec-websocket-key1">>, Req2),
+ {Key2, Req4} = cowboy_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},
@@ -101,7 +102,7 @@ websocket_upgrade(undefined, State, Req) ->
websocket_upgrade(Version, State, Req)
when Version =:= <<"7">>; Version =:= <<"8">>;
Version =:= <<"13">> ->
- {Key, Req2} = cowboy_req:header(<<"Sec-Websocket-Key">>, Req),
+ {Key, Req2} = cowboy_req:header(<<"sec-websocket-key">>, Req),
false = Key =:= undefined,
Challenge = hybi_challenge(Key),
IntVersion = list_to_integer(binary_to_list(Version)),