diff options
author | Loïc Hoguin <[email protected]> | 2011-11-04 10:38:04 +0100 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2011-11-04 10:38:04 +0100 |
commit | 77b35622570e3802da31df9f549875b60bd121cc (patch) | |
tree | 0f52a31aef8190043ef01c3c6665dd7ebc06e430 /src | |
parent | 68c1d886e5c4cb974b62b9c5fe7f21e6bbc5d557 (diff) | |
download | cowboy-77b35622570e3802da31df9f549875b60bd121cc.tar.gz cowboy-77b35622570e3802da31df9f549875b60bd121cc.tar.bz2 cowboy-77b35622570e3802da31df9f549875b60bd121cc.zip |
Rename cowboy_http:charset/2 to conneg/2 and use it for Accept-Encoding
Sorry I apparently used an outdated RFC when I was doing this.
Diffstat (limited to 'src')
-rw-r--r-- | src/cowboy_http.erl | 17 | ||||
-rw-r--r-- | src/cowboy_http_req.erl | 4 |
2 files changed, 11 insertions, 10 deletions
diff --git a/src/cowboy_http.erl b/src/cowboy_http.erl index 9b8a178..681f09f 100644 --- a/src/cowboy_http.erl +++ b/src/cowboy_http.erl @@ -17,7 +17,7 @@ %% Parsing. -export([list/2, nonempty_list/2, - media_range/2, charset/2, + media_range/2, conneg/2, token/2, token_ci/2, quoted_string/2]). %% Interpretation. @@ -196,23 +196,24 @@ accept_ext_value(Data, Fun, Type, SubType, Params, Quality, Acc, Attr) -> Type, SubType, Params, Quality, [{Attr, Value}|Acc]) end). -%% @doc Parse a charset, followed by an optional quality value. --spec charset(binary(), fun()) -> any(). -charset(Data, Fun) -> +%% @doc Parse a conneg header (Accept-Charset, Accept-Encoding), +%% followed by an optional quality value. +-spec conneg(binary(), fun()) -> any(). +conneg(Data, Fun) -> token_ci(Data, fun (_Rest, <<>>) -> {error, badarg}; - (Rest, Charset) -> + (Rest, Conneg) -> whitespace(Rest, fun (<< $;, Rest2/bits >>) -> whitespace(Rest2, fun (Rest3) -> qparam(Rest3, fun (Rest4, Quality) -> - Fun(Rest4, {Charset, Quality}) + Fun(Rest4, {Conneg, Quality}) end) end); (Rest2) -> - Fun(Rest2, {Charset, 1000}) + Fun(Rest2, {Conneg, 1000}) end) end). @@ -339,7 +340,7 @@ nonempty_charset_list_test_() -> {<<"unicode-1-1">>, 800} ]} ], - [{V, fun() -> R = nonempty_list(V, fun charset/2) end} || {V, R} <- Tests]. + [{V, fun() -> R = nonempty_list(V, fun conneg/2) end} || {V, R} <- Tests]. nonempty_token_list_test_() -> %% {Value, Result} diff --git a/src/cowboy_http_req.erl b/src/cowboy_http_req.erl index 3a3dd2f..064722f 100644 --- a/src/cowboy_http_req.erl +++ b/src/cowboy_http_req.erl @@ -219,12 +219,12 @@ parse_header(Name, Req, Default) when Name =:= 'Accept' -> parse_header(Name, Req, Default) when Name =:= 'Accept-Charset' -> parse_header(Name, Req, Default, fun (Value) -> - cowboy_http:nonempty_list(Value, fun cowboy_http:charset/2) + cowboy_http:nonempty_list(Value, fun cowboy_http:conneg/2) end); parse_header(Name, Req, Default) when Name =:= 'Accept-Encoding' -> parse_header(Name, Req, Default, fun (Value) -> - cowboy_http:list(Value, fun cowboy_http:token_ci/2) + cowboy_http:list(Value, fun cowboy_http:conneg/2) end); parse_header(Name, Req, Default) when Name =:= 'Connection' -> parse_header(Name, Req, Default, |