Debian Codegraph @

doc/src/manual/cowboy_req.set_resp_headers.asciidoc

raw
1 = cowboy_req:set_resp_headers(3)
2
3 == Name
4
5 cowboy_req:set_resp_headers - Set several response headers
6
7 == Description
8
9 [source,erlang]
10 ----
11 set_resp_headers(Headers, Req :: cowboy_req:req())
12 -> Req
13
14 Headers :: cowboy:http_headers() | [{binary(), iodata()}]
15 ----
16
17 Set several headers to be sent with the response.
18
19 The header name must be given as a lowercase binary string.
20 While header names are case insensitive, Cowboy requires them
21 to be given as lowercase to function properly.
22
23 Cowboy does not allow duplicate header names. Headers set
24 by this function may be overwritten by those set from the
25 reply functions. Likewise, headers set by this function may
26 overwrite headers that were set previously.
27
28 Use link:man:cowboy_req:set_resp_cookie(3)[cowboy_req:set_resp_cookie(3)]
29 instead of this function to set cookies.
30
31 == Arguments
32
33 Headers::
34
35 Headers as a map with names being lowercase binary strings,
36 and values as iodata; or as a list with the same requirements
37 for names and values.
38 +
39 When a list is given it is converted to its equivalent map,
40 with duplicate headers concatenated with a comma inserted
41 in-between. Support for lists is meant to simplify using
42 data from clients or other applications.
43 +
44 The set-cookie header must not be set using this function.
45
46 Req::
47
48 The Req object.
49
50 == Return value
51
52 A new Req object is returned.
53
54 The returned Req object must be used from that point onward,
55 otherwise the headers will not be sent in the response.
56
57 == Changelog
58
59 * *2.13*: The function now accepts a list of headers.
60 * *2.0*: Function introduced.
61
62 == Examples
63
64 .Set several response headers
65 [source,erlang]
66 ----
67 Req = cowboy_req:set_resp_headers(#{
68 <<"content-type">> => <<"text/html">>,
69 <<"content-encoding">> => <<"gzip">>
70 }, Req0).
71 ----
72
73 == See also
74
75 link:man:cowboy_req(3)[cowboy_req(3)],
76 link:man:cowboy_req:set_resp_cookie(3)[cowboy_req:set_resp_cookie(3)],
77 link:man:cowboy_req:set_resp_header(3)[cowboy_req:set_resp_header(3)],
78 link:man:cowboy_req:has_resp_header(3)[cowboy_req:has_resp_header(3)],
79 link:man:cowboy_req:resp_header(3)[cowboy_req:resp_header(3)],
80 link:man:cowboy_req:resp_headers(3)[cowboy_req:resp_headers(3)],
81 link:man:cowboy_req:delete_resp_header(3)[cowboy_req:delete_resp_header(3)],
82 link:man:cowboy_req:reply(3)[cowboy_req:reply(3)],
83 link:man:cowboy_req:stream_reply(3)[cowboy_req:stream_reply(3)]