aboutsummaryrefslogtreecommitdiffstats
path: root/src/cow_http_hd.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2014-12-13 13:36:39 +0200
committerLoïc Hoguin <[email protected]>2014-12-13 13:36:39 +0200
commit847b1bca21cc2ddec6b94f2a8f8924ad3f4be73a (patch)
tree07d534d64d25b108cf898345cb1e30ea9caaf924 /src/cow_http_hd.erl
parenta9a3bc7b66b72c088814c99f169a3ae67f37c901 (diff)
downloadcowlib-847b1bca21cc2ddec6b94f2a8f8924ad3f4be73a.tar.gz
cowlib-847b1bca21cc2ddec6b94f2a8f8924ad3f4be73a.tar.bz2
cowlib-847b1bca21cc2ddec6b94f2a8f8924ad3f4be73a.zip
Add cow_http_hd:parse_accept_encoding/1
From RFC7231.
Diffstat (limited to 'src/cow_http_hd.erl')
-rw-r--r--src/cow_http_hd.erl36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/cow_http_hd.erl b/src/cow_http_hd.erl
index 397a759..0e3e940 100644
--- a/src/cow_http_hd.erl
+++ b/src/cow_http_hd.erl
@@ -16,6 +16,7 @@
-export([parse_accept/1]).
-export([parse_accept_charset/1]).
+-export([parse_accept_encoding/1]).
-export([parse_connection/1]).
-export([parse_content_length/1]).
-export([parse_expect/1]).
@@ -317,6 +318,41 @@ horse_parse_accept_charset() ->
).
-endif.
+%% @doc Parse the Accept-Encoding header.
+
+-spec parse_accept_encoding(binary()) -> [{binary(), qvalue()}].
+parse_accept_encoding(Encoding) ->
+ conneg_list(Encoding, []).
+
+-ifdef(TEST).
+parse_accept_encoding_test_() ->
+ Tests = [
+ {<<>>, []},
+ {<<"*">>, [{<<"*">>, 1000}]},
+ {<<"compress, gzip">>, [
+ {<<"compress">>, 1000},
+ {<<"gzip">>, 1000}
+ ]},
+ {<<"compress;q=0.5, gzip;q=1.0">>, [
+ {<<"compress">>, 500},
+ {<<"gzip">>, 1000}
+ ]},
+ {<<"gzip;q=1.0, identity; q=0.5, *;q=0">>, [
+ {<<"gzip">>, 1000},
+ {<<"identity">>, 500},
+ {<<"*">>, 0}
+ ]}
+ ],
+ [{V, fun() -> R = parse_accept_encoding(V) end} || {V, R} <- Tests].
+-endif.
+
+-ifdef(PERF).
+horse_parse_accept_encoding() ->
+ horse:repeat(20000,
+ parse_accept_encoding(<<"gzip;q=1.0, identity; q=0.5, *;q=0">>)
+ ).
+-endif.
+
%% @doc Parse the Connection header.
-spec parse_connection(binary()) -> [binary()].