aboutsummaryrefslogtreecommitdiffstats
path: root/src/cow_http_hd.erl
diff options
context:
space:
mode:
authorAndrei Nesterov <[email protected]>2016-03-06 12:39:50 +0300
committerAndrei Nesterov <[email protected]>2016-06-07 21:36:14 +0300
commit772a26a429d4fe5716c207a667312e0fbc67f369 (patch)
tree38e071cff56ea032688ab64476cdf97dbd6a0dcf /src/cow_http_hd.erl
parentcd21feebdcaf7ee5da36cc495ad3cb7ac6d5b7c2 (diff)
downloadcowlib-772a26a429d4fe5716c207a667312e0fbc67f369.tar.gz
cowlib-772a26a429d4fe5716c207a667312e0fbc67f369.tar.bz2
cowlib-772a26a429d4fe5716c207a667312e0fbc67f369.zip
Add cow_http_hd:parse_access_control_request_headers/1
Diffstat (limited to 'src/cow_http_hd.erl')
-rw-r--r--src/cow_http_hd.erl39
1 files changed, 38 insertions, 1 deletions
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().