aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJohan Lövdahl <[email protected]>2016-11-13 15:39:40 +0100
committerLoïc Hoguin <[email protected]>2017-01-04 13:37:50 +0100
commit3f4e79d42f7a81fa3f8e790630f71570287c2be0 (patch)
treef3024f163a6a085e0fa35fa50c53cdff0a69a7e8 /src
parent42c95b1584c245d73e6ddc052a922c8e7c68dee2 (diff)
downloadcowboy-3f4e79d42f7a81fa3f8e790630f71570287c2be0.tar.gz
cowboy-3f4e79d42f7a81fa3f8e790630f71570287c2be0.tar.bz2
cowboy-3f4e79d42f7a81fa3f8e790630f71570287c2be0.zip
Add functions for getting and setting response headers
Diffstat (limited to 'src')
-rw-r--r--src/cowboy_req.erl30
1 files changed, 29 insertions, 1 deletions
diff --git a/src/cowboy_req.erl b/src/cowboy_req.erl
index ac93875..c2a85e5 100644
--- a/src/cowboy_req.erl
+++ b/src/cowboy_req.erl
@@ -59,8 +59,11 @@
%% Response.
-export([set_resp_cookie/3]).
-export([set_resp_cookie/4]).
+-export([resp_header/2]).
+-export([resp_header/3]).
+-export([resp_headers/1]).
-export([set_resp_header/3]).
-%% @todo set_resp_headers/2
+-export([set_resp_headers/2]).
-export([has_resp_header/2]).
%% @todo resp_header
-export([delete_resp_header/2]).
@@ -570,6 +573,31 @@ set_resp_header(Name, Value, Req=#{resp_headers := RespHeaders}) ->
set_resp_header(Name,Value, Req) ->
Req#{resp_headers => #{Name => Value}}.
+-spec set_resp_headers(cowboy:http_headers(), Req)
+ -> Req when Req::req().
+set_resp_headers(Headers, Req=#{resp_headers := RespHeaders}) ->
+ Req#{resp_headers => maps:merge(RespHeaders, Headers)};
+set_resp_headers(Headers, Req) ->
+ Req#{resp_headers => Headers}.
+
+
+-spec resp_header(binary(), req()) -> binary() | undefined.
+resp_header(Name, Req) ->
+ resp_header(Name, Req, undefined).
+
+-spec resp_header(binary(), req(), Default)
+ -> binary() | Default when Default::any().
+resp_header(Name, #{resp_headers := Headers}, Default) ->
+ maps:get(Name, Headers, Default);
+resp_header(_, #{}, Default) ->
+ Default.
+
+-spec resp_headers(req()) -> cowboy:http_headers().
+resp_headers(#{resp_headers := RespHeaders}) ->
+ RespHeaders;
+resp_headers(#{}) ->
+ #{}.
+
-spec set_resp_body(resp_body(), Req) -> Req when Req::req().
set_resp_body(Body, Req) ->
Req#{resp_body => Body}.