aboutsummaryrefslogtreecommitdiffstats
path: root/src/cow_http_hd.erl
diff options
context:
space:
mode:
authorAndrei Nesterov <[email protected]>2016-03-05 21:59:32 +0300
committerAndrei Nesterov <[email protected]>2016-06-07 21:36:15 +0300
commit6d84ddf189b77d0317bf3db0135cfc3f83d7285f (patch)
treee3f9ca30db9cd4168d51b13831a338d9d0a4b900 /src/cow_http_hd.erl
parent772a26a429d4fe5716c207a667312e0fbc67f369 (diff)
downloadcowlib-6d84ddf189b77d0317bf3db0135cfc3f83d7285f.tar.gz
cowlib-6d84ddf189b77d0317bf3db0135cfc3f83d7285f.tar.bz2
cowlib-6d84ddf189b77d0317bf3db0135cfc3f83d7285f.zip
Add cow_http_hd:parse_access_control_request_method/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 a32024e..4eac48a 100644
--- a/src/cow_http_hd.erl
+++ b/src/cow_http_hd.erl
@@ -28,7 +28,7 @@
% @todo -export([parse_access_control_expose_headers/1]). CORS
% @todo -export([parse_access_control_max_age/1]). CORS
-export([parse_access_control_request_headers/1]).
-% @todo -export([parse_access_control_request_method/1]). CORS
+-export([parse_access_control_request_method/1]).
-export([parse_age/1]).
-export([parse_allow/1]).
% @todo -export([parse_alternates/1]). RFC2295
@@ -734,6 +734,43 @@ horse_parse_access_control_request_headers() ->
).
-endif.
+%% @doc Parse the Access-Control-Request-Method header.
+
+-spec parse_access_control_request_method(binary()) -> binary().
+parse_access_control_request_method(Method) ->
+ true = <<>> =/= Method,
+ ok = validate_token(Method),
+ Method.
+
+validate_token(<< C, R/bits >>) when ?IS_TOKEN(C) -> validate_token(R);
+validate_token(<<>>) -> ok.
+
+-ifdef(TEST).
+parse_access_control_request_method_test_() ->
+ Tests = [
+ <<"GET">>,
+ <<"HEAD">>,
+ <<"POST">>,
+ <<"PUT">>,
+ <<"DELETE">>,
+ <<"TRACE">>,
+ <<"CONNECT">>,
+ <<"whatever">>
+ ],
+ [{V, fun() -> R = parse_access_control_request_method(V) end} || {V, R} <- Tests].
+
+parse_access_control_request_method_error_test_() ->
+ Tests = [
+ <<>>
+ ],
+ [{V, fun() -> {'EXIT', _} = (catch parse_access_control_request_method(V)) end} || V <- Tests].
+
+horse_parse_access_control_request_method() ->
+ horse:repeat(200000,
+ parse_access_control_request_method(<<"POST">>)
+ ).
+-endif.
+
%% @doc Parse the Age header.
-spec parse_age(binary()) -> non_neg_integer().