From 3f4e79d42f7a81fa3f8e790630f71570287c2be0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20L=C3=B6vdahl?= Date: Sun, 13 Nov 2016 15:39:40 +0100 Subject: Add functions for getting and setting response headers --- test/handlers/resp_h.erl | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'test/handlers/resp_h.erl') 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 -- cgit v1.2.3