aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/handlers/resp_h.erl23
-rw-r--r--test/req_SUITE.erl19
2 files changed, 42 insertions, 0 deletions
diff --git a/test/handlers/resp_h.erl b/test/handlers/resp_h.erl
index bb64906..97423c0 100644
--- a/test/handlers/resp_h.erl
+++ b/test/handlers/resp_h.erl
@@ -25,6 +25,29 @@ do(<<"set_resp_cookie4">>, Req0, Opts) ->
do(<<"set_resp_header">>, Req0, Opts) ->
Req = cowboy_req:set_resp_header(<<"content-type">>, <<"text/plain">>, Req0),
{ok, cowboy_req:reply(200, #{}, "OK", Req), Opts};
+do(<<"set_resp_headers">>, Req0, Opts) ->
+ Req = cowboy_req:set_resp_headers(#{<<"x-header-test1">> => <<"test1">>, <<"x-header-test2">> => <<"test2">>}, Req0),
+ {ok, cowboy_req:reply(200, #{}, "OK", Req), Opts};
+do(<<"resp_headers">>, Req0, Opts) ->
+ Req1 = cowboy_req:set_resp_header(<<"x-header-test1">>, <<"test1">>, Req0),
+ Req2 = cowboy_req:set_resp_headers(#{<<"x-header-test2">> => <<"test2">>, <<"x-header-test3">> => <<"test3">>}, Req1),
+ Headers = cowboy_req:resp_headers(Req2),
+ true = maps:is_key(<<"x-header-test1">>, Headers),
+ true = maps:is_key(<<"x-header-test2">>, Headers),
+ true = maps:is_key(<<"x-header-test3">>, Headers),
+ {ok, cowboy_req:reply(200, #{}, "OK", Req2), Opts};
+do(<<"resp_header_defined">>, Req0, Opts) ->
+ Req1 = cowboy_req:set_resp_header(<<"x-header-test1">>, <<"test1">>, Req0),
+ <<"test1">> = cowboy_req:resp_header(<<"x-header-test1">>, Req1),
+ <<"test1">> = cowboy_req:resp_header(<<"x-header-test1">>, Req1, foo),
+ {ok, cowboy_req:reply(200, #{}, "OK", Req0), Opts};
+do(<<"resp_header_default">>, Req0, Opts) ->
+ undefined = cowboy_req:resp_header(<<"x-header-test1">>, Req0),
+ <<"ok">> = cowboy_req:resp_header(<<"x-header-test1">>, Req0, <<"ok">>),
+ {ok, cowboy_req:reply(200, #{}, "OK", Req0), Opts};
+do(<<"resp_headers_empty">>, Req0, Opts) ->
+ #{} = cowboy_req:resp_headers(Req0),
+ {ok, cowboy_req:reply(200, #{}, "OK", Req0), Opts};
do(<<"set_resp_body">>, Req0, Opts) ->
Arg = cowboy_req:binding(arg, Req0),
Req1 = case Arg of
diff --git a/test/req_SUITE.erl b/test/req_SUITE.erl
index 16a9178..809e9f0 100644
--- a/test/req_SUITE.erl
+++ b/test/req_SUITE.erl
@@ -487,6 +487,25 @@ set_resp_header(Config) ->
true = lists:keymember(<<"content-type">>, 1, Headers),
ok.
+set_resp_headers(Config) ->
+ doc("Response using set_resp_headers."),
+ {200, Headers, <<"OK">>} = do_get("/resp/set_resp_headers", Config),
+ true = lists:keymember(<<"x-header-test1">>, 1, Headers),
+ true = lists:keymember(<<"x-header-test2">>, 1, Headers),
+ ok.
+
+resp_header(Config) ->
+ doc("Response header with/without default."),
+ {200, _, <<"OK">>} = do_get("/resp/resp_header_defined", Config),
+ {200, _, <<"OK">>} = do_get("/resp/resp_header_default", Config),
+ ok.
+
+resp_headers(Config) ->
+ doc("Get all response headers."),
+ {200, _, <<"OK">>} = do_get("/resp/resp_headers", Config),
+ {200, _, <<"OK">>} = do_get("/resp/resp_headers_empty", Config),
+ ok.
+
set_resp_body(Config) ->
doc("Response using set_resp_body."),
{200, _, <<"OK">>} = do_get("/resp/set_resp_body", Config),