diff options
author | Loïc Hoguin <[email protected]> | 2014-12-26 10:53:59 +0100 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2014-12-26 10:53:59 +0100 |
commit | 6b97792d8990ceb816b5fa9a5f133fa3936df446 (patch) | |
tree | 392651d4e06952054f293dae9fd8740d22b937a5 | |
parent | 35e1391a570ca1f1b1b0df03e70e67d113da8818 (diff) | |
download | cowlib-6b97792d8990ceb816b5fa9a5f133fa3936df446.tar.gz cowlib-6b97792d8990ceb816b5fa9a5f133fa3936df446.tar.bz2 cowlib-6b97792d8990ceb816b5fa9a5f133fa3936df446.zip |
Add cow_http_hd:parse_vary/1
From RFC7231.
-rw-r--r-- | src/cow_http_hd.erl | 25 |
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. |