diff options
author | Andrei Nesterov <[email protected]> | 2016-03-06 18:57:28 +0300 |
---|---|---|
committer | Andrei Nesterov <[email protected]> | 2016-06-07 21:36:15 +0300 |
commit | 987f4d5e84e5f129cea5460a5d9a8423e0e783f9 (patch) | |
tree | 6004bd4d5742fef265dd0d0b19d266fa1c41d55a /src/cow_http_hd.erl | |
parent | 85f3208c34ef8774eeb0cc49576c82dd01b8d689 (diff) | |
download | cowlib-987f4d5e84e5f129cea5460a5d9a8423e0e783f9.tar.gz cowlib-987f4d5e84e5f129cea5460a5d9a8423e0e783f9.tar.bz2 cowlib-987f4d5e84e5f129cea5460a5d9a8423e0e783f9.zip |
Add cow_http_hd:access_control_allow_methods/1
Diffstat (limited to 'src/cow_http_hd.erl')
-rw-r--r-- | src/cow_http_hd.erl | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/cow_http_hd.erl b/src/cow_http_hd.erl index 0baacab..80a2f8a 100644 --- a/src/cow_http_hd.erl +++ b/src/cow_http_hd.erl @@ -114,6 +114,7 @@ %% Building. -export([access_control_allow_credentials/0]). -export([access_control_allow_headers/1]). +-export([access_control_allow_methods/1]). -type etag() :: {weak | strong, binary()}. -export_type([etag/0]). @@ -3251,6 +3252,34 @@ horse_access_control_allow_headers() -> ). -endif. +%% @doc Build the Access-Control-Allow-Methods header. + +-spec access_control_allow_methods([binary()]) -> iodata(). +access_control_allow_methods(Methods) -> + join_token_list(nonempty(Methods)). + +-ifdef(TEST). +access_control_allow_methods_test_() -> + Tests = [ + {[<<"GET">>], <<"GET">>}, + {[<<"GET">>, <<"POST">>, <<"DELETE">>], <<"GET, POST, DELETE">>} + ], + [{lists:flatten(io_lib:format("~p", [V])), + fun() -> R = iolist_to_binary(access_control_allow_methods(V)) end} || {V, R} <- Tests]. + +access_control_allow_methods_error_test_() -> + Tests = [ + [] + ], + [{lists:flatten(io_lib:format("~p", [V])), + fun() -> {'EXIT', _} = (catch access_control_allow_methods(V)) end} || V <- Tests]. + +horse_access_control_allow_methods() -> + horse:repeat(200000, + access_control_allow_methods([<<"GET">>, <<"POST">>, <<"DELETE">>]) + ). +-endif. + %% Internal. %% Only return if the list is not empty. |