aboutsummaryrefslogtreecommitdiffstats
path: root/src/cow_http_hd.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2014-12-26 10:53:59 +0100
committerLoïc Hoguin <[email protected]>2014-12-26 10:53:59 +0100
commit6b97792d8990ceb816b5fa9a5f133fa3936df446 (patch)
tree392651d4e06952054f293dae9fd8740d22b937a5 /src/cow_http_hd.erl
parent35e1391a570ca1f1b1b0df03e70e67d113da8818 (diff)
downloadcowlib-6b97792d8990ceb816b5fa9a5f133fa3936df446.tar.gz
cowlib-6b97792d8990ceb816b5fa9a5f133fa3936df446.tar.bz2
cowlib-6b97792d8990ceb816b5fa9a5f133fa3936df446.zip
Add cow_http_hd:parse_vary/1
From RFC7231.
Diffstat (limited to 'src/cow_http_hd.erl')
-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.