aboutsummaryrefslogtreecommitdiffstats
path: root/doc/src/manual/cowboy_req.inform.asciidoc
blob: 1770c14a5b1fc21618572058170498f76e9150ba (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
= cowboy_req:inform(3)

== Name

cowboy_req:inform - Send an informational response

== Description

[source,erlang]
----
inform(Status, Req :: cowboy_req:req())
    -> inform(StatusCode, #{}, Req)

inform(Status, Headers, Req :: cowboy_req:req())
    -> ok

Status  :: cowboy:http_status()
Headers :: cowboy:http_headers()
----

Send an informational response.

Informational responses use a status code between 100 and 199.
They cannot include a body. This function will not use any
of the previously set headers. All headers to be sent must
be given directly.

Any number of informational responses can be sent as long as
they are sent before the proper response. Attempting to use
this function after sending a normal response will result
in an error.

The header names must be given as lowercase binary strings.
While header names are case insensitive, Cowboy requires them
to be given as lowercase to function properly.

== Arguments

Status::

The status code for the response.

Headers::

The response headers.
+
Header names must be given as lowercase binary strings.

Req::

The Req object.

== Return value

The atom `ok` is always returned. It can be safely ignored.

== Changelog

* *2.1*: Function introduced.

== Examples

.Send an informational response
[source,erlang]
----
Req = cowboy_req:inform(102, Req0).
----

.Send an informational response with headers
[source,erlang]
----
Req = cowboy_req:inform(103, #{
    <<"link">> => <<"</style.css>; rel=preload; as=style">>,
    <<"link">> => <<"</script.js>; rel=preload; as=script">>
}, Req0).
----

== See also

link:man:cowboy_req(3)[cowboy_req(3)],
link:man:cowboy_req:reply(3)[cowboy_req:reply(3)],
link:man:cowboy_req:stream_reply(3)[cowboy_req:stream_reply(3)],
link:man:cowboy_req:push(3)[cowboy_req:push(3)]