aboutsummaryrefslogtreecommitdiffstats
path: root/src/cow_http_hd.erl
diff options
context:
space:
mode:
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()].