From 6b97792d8990ceb816b5fa9a5f133fa3936df446 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Fri, 26 Dec 2014 10:53:59 +0100 Subject: Add cow_http_hd:parse_vary/1 From RFC7231. --- src/cow_http_hd.erl | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/cow_http_hd.erl') 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. -- cgit v1.2.3