aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/cow_http_hd.erl42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/cow_http_hd.erl b/src/cow_http_hd.erl
index 6d6562e..584309c 100644
--- a/src/cow_http_hd.erl
+++ b/src/cow_http_hd.erl
@@ -18,6 +18,7 @@
-export([parse_accept_charset/1]).
-export([parse_accept_encoding/1]).
-export([parse_accept_language/1]).
+-export([parse_accept_ranges/1]).
-export([parse_age/1]).
-export([parse_allow/1]).
-export([parse_cache_control/1]).
@@ -696,6 +697,47 @@ horse_parse_accept_language() ->
).
-endif.
+%% @doc Parse the Accept-Ranges header.
+
+-spec parse_accept_ranges(binary()) -> [binary()].
+parse_accept_ranges(<<"none">>) -> [];
+parse_accept_ranges(<<"bytes">>) -> [<<"bytes">>];
+parse_accept_ranges(AcceptRanges) ->
+ nonempty(token_ci_list(AcceptRanges, [])).
+
+-ifdef(TEST).
+parse_accept_ranges_test_() ->
+ Tests = [
+ {<<"bytes">>, [<<"bytes">>]},
+ {<<"none">>, []},
+ {<<"bytes, pages, kilos">>, [<<"bytes">>, <<"pages">>, <<"kilos">>]}
+ ],
+ [{V, fun() -> R = parse_accept_ranges(V) end} || {V, R} <- Tests].
+
+parse_accept_ranges_error_test_() ->
+ Tests = [
+ <<>>
+ ],
+ [{V, fun() -> {'EXIT', _} = (catch parse_accept_ranges(V)) end} || V <- Tests].
+-endif.
+
+-ifdef(PERF).
+horse_parse_accept_ranges_none() ->
+ horse:repeat(200000,
+ parse_accept_ranges(<<"none">>)
+ ).
+
+horse_parse_accept_ranges_bytes() ->
+ horse:repeat(200000,
+ parse_accept_ranges(<<"bytes">>)
+ ).
+
+horse_parse_accept_ranges_other() ->
+ horse:repeat(200000,
+ parse_accept_ranges(<<"bytes, pages, kilos">>)
+ ).
+-endif.
+
%% @doc Parse the Age header.
-spec parse_age(binary()) -> non_neg_integer().