aboutsummaryrefslogtreecommitdiffstats
path: root/src/cowboy_http_websocket.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2011-10-05 03:17:13 +0200
committerLoïc Hoguin <[email protected]>2011-10-05 13:32:20 +0200
commitbf5c2717bc49d82f6415536c7ff0be2e1d8361a5 (patch)
treeb5bbbf1e3e25315438c5afc1d21cf017c6e2225b /src/cowboy_http_websocket.erl
parent9a775cce3c2cdab064dd79df29914296cf642a8d (diff)
downloadcowboy-bf5c2717bc49d82f6415536c7ff0be2e1d8361a5.tar.gz
cowboy-bf5c2717bc49d82f6415536c7ff0be2e1d8361a5.tar.bz2
cowboy-bf5c2717bc49d82f6415536c7ff0be2e1d8361a5.zip
Parse 'Connection' headers as a list of tokens
Replaces the 'Connection' interpretation in cowboy_http_protocol from raw value to the parsed value, looking for a single token matching close/keep-alive instead of the whole raw value (which could contain more than one token, for example with Firefox 6+ using websocket). Introduce the functions cowboy_http_req:parse_header/2 and /3 to semantically parse the header values and return a proper Erlang term.
Diffstat (limited to 'src/cowboy_http_websocket.erl')
-rw-r--r--src/cowboy_http_websocket.erl7
1 files changed, 3 insertions, 4 deletions
diff --git a/src/cowboy_http_websocket.erl b/src/cowboy_http_websocket.erl
index 2a1f3e4..8b2fd34 100644
--- a/src/cowboy_http_websocket.erl
+++ b/src/cowboy_http_websocket.erl
@@ -76,10 +76,9 @@ upgrade(ListenerPid, Handler, Opts, Req) ->
%% instead of having ugly code like this case here.
-spec websocket_upgrade(#state{}, #http_req{}) -> {ok, #state{}, #http_req{}}.
websocket_upgrade(State, Req) ->
- case cowboy_http_req:header('Connection', Req) of
- {<<"Upgrade">>, Req2} -> ok;
- {<<"keep-alive, Upgrade">>, Req2} -> ok %% @todo Temp. For Firefox 6.
- end,
+ {tokens, ConnTokens, Req2}
+ = cowboy_http_req:parse_header('Connection', Req),
+ true = lists:member(<<"Upgrade">>, ConnTokens),
{Version, Req3} = cowboy_http_req:header(<<"Sec-Websocket-Version">>, Req2),
websocket_upgrade(Version, State, Req3).