aboutsummaryrefslogtreecommitdiffstats
path: root/src/cow_http_hd.erl
diff options
context:
space:
mode:
authorAndrei Nesterov <[email protected]>2016-03-06 18:50:53 +0300
committerAndrei Nesterov <[email protected]>2016-06-07 21:36:15 +0300
commitd670823e87ff7927638176d5025ae8ff227785ab (patch)
treefee92486e0cc4dcd67073ac555482e01e330a9ab /src/cow_http_hd.erl
parent056d26b4d8d65f9bd83c594f307602eac5f2312a (diff)
downloadcowlib-d670823e87ff7927638176d5025ae8ff227785ab.tar.gz
cowlib-d670823e87ff7927638176d5025ae8ff227785ab.tar.bz2
cowlib-d670823e87ff7927638176d5025ae8ff227785ab.zip
Add cow_http_hd:access_control_expose_headers/1
Diffstat (limited to 'src/cow_http_hd.erl')
-rw-r--r--src/cow_http_hd.erl29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/cow_http_hd.erl b/src/cow_http_hd.erl
index 8e258f9..4207b19 100644
--- a/src/cow_http_hd.erl
+++ b/src/cow_http_hd.erl
@@ -116,6 +116,7 @@
-export([access_control_allow_headers/1]).
-export([access_control_allow_methods/1]).
-export([access_control_allow_origin/1]).
+-export([access_control_expose_headers/1]).
-type etag() :: {weak | strong, binary()}.
-export_type([etag/0]).
@@ -3315,6 +3316,34 @@ horse_access_control_allow_origin() ->
).
-endif.
+%% @doc Build the Access-Control-Expose-Headers header.
+
+-spec access_control_expose_headers([binary()]) -> iodata().
+access_control_expose_headers(Headers) ->
+ join_token_list(nonempty(Headers)).
+
+-ifdef(TEST).
+access_control_expose_headers_test_() ->
+ Tests = [
+ {[<<"accept">>], <<"accept">>},
+ {[<<"accept">>, <<"authorization">>, <<"content-type">>], <<"accept, authorization, content-type">>}
+ ],
+ [{lists:flatten(io_lib:format("~p", [V])),
+ fun() -> R = iolist_to_binary(access_control_expose_headers(V)) end} || {V, R} <- Tests].
+
+access_control_expose_headers_error_test_() ->
+ Tests = [
+ []
+ ],
+ [{lists:flatten(io_lib:format("~p", [V])),
+ fun() -> {'EXIT', _} = (catch access_control_expose_headers(V)) end} || V <- Tests].
+
+horse_access_control_expose_headers() ->
+ horse:repeat(200000,
+ access_control_expose_headers([<<"accept">>, <<"authorization">>, <<"content-type">>])
+ ).
+-endif.
+
%% Internal.
%% Only return if the list is not empty.