cowboy_req.set_resp_header.asciidoc 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. = cowboy_req:set_resp_header(3)
  2. == Name
  3. cowboy_req:set_resp_header - Set a response header
  4. == Description
  5. [source,erlang]
  6. ----
  7. set_resp_header(Name, Value, Req :: cowboy_req:req())
  8. -> Req
  9. Name :: binary() %% lowercase; case insensitive
  10. Value :: iodata() %% case depends on header
  11. ----
  12. Set a header to be sent with the response.
  13. The header name must be given as a lowercase binary string.
  14. While header names are case insensitive, Cowboy requires them
  15. to be given as lowercase to function properly.
  16. Cowboy does not allow duplicate header names. Headers set
  17. by this function may be overwritten by those set from the
  18. reply functions.
  19. Use link:man:cowboy_req:set_resp_cookie(3)[cowboy_req:set_resp_cookie(3)]
  20. instead of this function to set cookies.
  21. == Arguments
  22. Name::
  23. Header name as a lowercase binary string.
  24. Value::
  25. Header value.
  26. Req::
  27. The Req object.
  28. == Return value
  29. A new Req object is returned.
  30. The returned Req object must be used from that point onward,
  31. otherwise the header will not be sent in the response.
  32. == Changelog
  33. * *1.0*: Function introduced.
  34. == Examples
  35. .Set a header in the response
  36. [source,erlang]
  37. ----
  38. Req = cowboy_req:set_resp_header(<<"allow">>, "GET", Req0).
  39. ----
  40. .Construct a header using iolists
  41. [source,erlang]
  42. ----
  43. Req = cowboy_req:set_resp_header(<<"allow">>,
  44. [allowed_methods(), ", OPTIONS"], Req0).
  45. ----
  46. == See also
  47. link:man:cowboy_req(3)[cowboy_req(3)],
  48. link:man:cowboy_req:set_resp_cookie(3)[cowboy_req:set_resp_cookie(3)],
  49. link:man:cowboy_req:set_resp_headers(3)[cowboy_req:set_resp_headers(3)],
  50. link:man:cowboy_req:has_resp_header(3)[cowboy_req:has_resp_header(3)],
  51. link:man:cowboy_req:resp_header(3)[cowboy_req:resp_header(3)],
  52. link:man:cowboy_req:resp_headers(3)[cowboy_req:resp_headers(3)],
  53. link:man:cowboy_req:delete_resp_header(3)[cowboy_req:delete_resp_header(3)],
  54. link:man:cowboy_req:reply(3)[cowboy_req:reply(3)],
  55. link:man:cowboy_req:stream_reply(3)[cowboy_req:stream_reply(3)]