diff options
author | Loïc Hoguin <[email protected]> | 2011-10-05 03:17:13 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2011-10-05 13:32:20 +0200 |
commit | bf5c2717bc49d82f6415536c7ff0be2e1d8361a5 (patch) | |
tree | b5bbbf1e3e25315438c5afc1d21cf017c6e2225b /src/cowboy_http_protocol.erl | |
parent | 9a775cce3c2cdab064dd79df29914296cf642a8d (diff) | |
download | cowboy-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_protocol.erl')
-rw-r--r-- | src/cowboy_http_protocol.erl | 23 |
1 files changed, 7 insertions, 16 deletions
diff --git a/src/cowboy_http_protocol.erl b/src/cowboy_http_protocol.erl index 8f6ab35..dc226a6 100644 --- a/src/cowboy_http_protocol.erl +++ b/src/cowboy_http_protocol.erl @@ -158,10 +158,13 @@ header({http_header, _I, 'Host', _R, RawHost}, Req=#http_req{ %% Ignore Host headers if we already have it. header({http_header, _I, 'Host', _R, _V}, Req, State) -> parse_header(Req, State); -header({http_header, _I, 'Connection', _R, Connection}, Req, State) -> - ConnAtom = connection_to_atom(Connection), - parse_header(Req#http_req{connection=ConnAtom, - headers=[{'Connection', Connection}|Req#http_req.headers]}, State); +header({http_header, _I, 'Connection', _R, Connection}, + Req=#http_req{headers=Headers}, State) -> + Req2 = Req#http_req{headers=[{'Connection', Connection}|Headers]}, + {tokens, ConnTokens, Req3} + = cowboy_http_req:parse_header('Connection', Req2), + ConnAtom = cowboy_http:connection_to_atom(ConnTokens), + parse_header(Req3#http_req{connection=ConnAtom}, State); header({http_header, _I, Field, _R, Value}, Req, State) -> Field2 = format_header(Field), parse_header(Req#http_req{headers=[{Field2, Value}|Req#http_req.headers]}, @@ -304,18 +307,6 @@ terminate(#state{socket=Socket, transport=Transport}) -> version_to_connection({1, 1}) -> keepalive; version_to_connection(_Any) -> close. -%% @todo Connection can take more than one value. --spec connection_to_atom(binary()) -> keepalive | close. -connection_to_atom(<<"keep-alive">>) -> - keepalive; -connection_to_atom(<<"close">>) -> - close; -connection_to_atom(Connection) -> - case cowboy_bstr:to_lower(Connection) of - <<"close">> -> close; - _Any -> keepalive - end. - -spec default_port(atom()) -> 80 | 443. default_port(ssl) -> 443; default_port(_) -> 80. |