0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-15 20:50:24 +00:00

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.
This commit is contained in:
Loïc Hoguin 2011-10-05 03:17:13 +02:00
parent 9a775cce3c
commit bf5c2717bc
5 changed files with 184 additions and 20 deletions

View file

@ -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).