From 772a26a429d4fe5716c207a667312e0fbc67f369 Mon Sep 17 00:00:00 2001 From: Andrei Nesterov Date: Sun, 6 Mar 2016 12:39:50 +0300 Subject: Add cow_http_hd:parse_access_control_request_headers/1 --- src/cow_http_hd.erl | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/cow_http_hd.erl b/src/cow_http_hd.erl index 2d20799..a32024e 100644 --- a/src/cow_http_hd.erl +++ b/src/cow_http_hd.erl @@ -27,7 +27,7 @@ % @todo -export([parse_access_control_allow_origin/1]). CORS % @todo -export([parse_access_control_expose_headers/1]). CORS % @todo -export([parse_access_control_max_age/1]). CORS -% @todo -export([parse_access_control_request_headers/1]). CORS +-export([parse_access_control_request_headers/1]). % @todo -export([parse_access_control_request_method/1]). CORS -export([parse_age/1]). -export([parse_allow/1]). @@ -697,6 +697,43 @@ horse_parse_accept_ranges_other() -> ). -endif. +%% @doc Parse the Access-Control-Request-Headers header. + +-spec parse_access_control_request_headers(binary()) -> [binary()]. +parse_access_control_request_headers(Headers) -> + token_ci_list(Headers, []). + +-ifdef(TEST). +headers() -> + ?LET(L, + list({ows(), ows(), token()}), + case L of + [] -> {[], <<>>}; + _ -> + << _, Headers/binary >> = iolist_to_binary([[OWS1, $,, OWS2, M] || {OWS1, OWS2, M} <- L]), + {[?LOWER(M) || {_, _, M} <- L], Headers} + end). + +prop_parse_access_control_request_headers() -> + ?FORALL({L, Headers}, + headers(), + L =:= parse_access_control_request_headers(Headers)). + +parse_access_control_request_headers_test_() -> + Tests = [ + {<<>>, []}, + {<<"Content-Type">>, [<<"content-type">>]}, + {<<"accept, authorization, content-type">>, [<<"accept">>, <<"authorization">>, <<"content-type">>]}, + {<<"accept,, , authorization,content-type">>, [<<"accept">>, <<"authorization">>, <<"content-type">>]} + ], + [{V, fun() -> R = parse_access_control_request_headers(V) end} || {V, R} <- Tests]. + +horse_parse_access_control_request_headers() -> + horse:repeat(200000, + parse_access_control_request_headers(<<"accept, authorization, content-type">>) + ). +-endif. + %% @doc Parse the Age header. -spec parse_age(binary()) -> non_neg_integer(). -- cgit v1.2.3