aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2025-02-10 18:43:17 +0100
committerLoïc Hoguin <[email protected]>2025-02-10 18:43:17 +0100
commita277d9160cf792fa74b70108d376e6fb65d42056 (patch)
tree7aeb04ae3d59d0c8b93a6200773c05b054c2d80b
parent8e02c78464c86d427c2bd0bb449d17e7876b9903 (diff)
downloadcowlib-a277d9160cf792fa74b70108d376e6fb65d42056.tar.gz
cowlib-a277d9160cf792fa74b70108d376e6fb65d42056.tar.bz2
cowlib-a277d9160cf792fa74b70108d376e6fb65d42056.zip
Add cow_http_hd:allow/1
-rw-r--r--src/cow_http_hd.erl17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/cow_http_hd.erl b/src/cow_http_hd.erl
index f0e4fba..c2b5806 100644
--- a/src/cow_http_hd.erl
+++ b/src/cow_http_hd.erl
@@ -40,6 +40,7 @@
-export([parse_access_control_request_method/1]).
-export([parse_age/1]).
-export([parse_allow/1]).
+-export([allow/1]).
% @todo -export([parse_alternates/1]). RFC2295
% @todo -export([parse_authentication_info/1]). RFC2617
-export([parse_authorization/1]).
@@ -1018,6 +1019,22 @@ horse_parse_allow() ->
).
-endif.
+-spec allow([binary()]) -> binary().
+allow([]) ->
+ <<>>;
+allow(Methods) ->
+ << ", ", Allow/binary >> = << << ", ", M/binary >> || M <- Methods >>,
+ Allow.
+
+-ifdef(TEST).
+allow_test_() ->
+ Tests = [
+ {[], <<>>},
+ {[<<"GET">>, <<"HEAD">>, <<"PUT">>], <<"GET, HEAD, PUT">>}
+ ],
+ [{R, fun() -> R = allow(V) end} || {V, R} <- Tests].
+-endif.
+
%% Authorization header.
%%
%% We support Basic, Digest and Bearer schemes only.