aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/cow_http_hd.erl25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/cow_http_hd.erl b/src/cow_http_hd.erl
index e94dabc..2c51fcc 100644
--- a/src/cow_http_hd.erl
+++ b/src/cow_http_hd.erl
@@ -45,6 +45,7 @@
-export([parse_trailer/1]).
-export([parse_transfer_encoding/1]).
-export([parse_upgrade/1]).
+-export([parse_vary/1]).
-type etag() :: {weak | strong, binary()}.
-export_type([etag/0]).
@@ -2371,6 +2372,30 @@ parse_upgrade_error_test_() ->
|| V <- Tests].
-endif.
+%% @doc Parse the Vary header.
+
+-spec parse_vary(binary()) -> '*' | [binary()].
+parse_vary(<<"*">>) ->
+ '*';
+parse_vary(Vary) ->
+ nonempty(token_ci_list(Vary, [])).
+
+-ifdef(TEST).
+parse_vary_test_() ->
+ Tests = [
+ {<<"*">>, '*'},
+ {<<"Accept-Encoding">>, [<<"accept-encoding">>]},
+ {<<"accept-encoding, accept-language">>, [<<"accept-encoding">>, <<"accept-language">>]}
+ ],
+ [{V, fun() -> R = parse_vary(V) end} || {V, R} <- Tests].
+
+parse_vary_error_test_() ->
+ Tests = [
+ <<>>
+ ],
+ [{V, fun() -> {'EXIT', _} = (catch parse_vary(V)) end} || V <- Tests].
+-endif.
+
%% Internal.
%% Only return if the list is not empty.