Debian Codegraph @

doc/src/manual/cowboy_req.push.asciidoc

raw
1 = cowboy_req:push(3)
2
3 == Name
4
5 cowboy_req:push - Push a resource to the client
6
7 == Description
8
9 [source,erlang]
10 ----
11 push(Path, Headers, Req :: cowboy_req:req())
12 -> push(Path, Headers, Req, #{})
13
14 push(Path, Headers, Req :: cowboy_req:req(), Opts)
15 -> ok
16
17 Path :: iodata() %% case sensitive
18 Headers :: cowboy:http_headers()
19 Opts :: cowboy_req:push_opts()
20 ----
21
22 Push a resource to the client.
23
24 Cowboy handles push requests the same way as if they came
25 from the client, including the creation of a request handling
26 process, routing and middlewares and so on.
27
28 This function does nothing when the HTTP/1.1 protocol is
29 used. You may call it safely without first checking whether
30 the connection uses HTTP/2.
31
32 The header names must be given as lowercase binary strings.
33 While header names are case insensitive, Cowboy requires them
34 to be given as lowercase to function properly.
35
36 Note that the headers must be the headers the client is expected
37 to send if it were to perform the request. They are therefore
38 request headers, and not response headers.
39
40 By default, Cowboy will use the GET method, an empty query string,
41 and take the scheme, host and port directly from the current
42 request's URI. You can override them by passing options.
43
44 Note that clients may cancel the push or ignore it entirely.
45 For example browsers may ignore the resource when the connection
46 is not considered secure.
47
48 It is not possible to push resources after sending a response.
49 Any attempt will result in an error.
50
51 == Arguments
52
53 Path::
54
55 The status code for the response.
56
57 Headers::
58
59 The response headers.
60 +
61 Header names must be given as lowercase binary strings.
62
63 Req::
64
65 The Req object.
66
67 Opts::
68
69 Customize the HTTP method or the URI scheme, host, port
70 or query string.
71
72 == Return value
73
74 The atom `ok` is always returned. It can be safely ignored.
75
76 == Changelog
77
78 * *2.0*: Function introduced.
79
80 == Examples
81
82 .Push a resource
83 [source,erlang]
84 ----
85 cowboy_req:push("/static/style.css", #{
86 <<"accept">> => <<"text/css">>
87 }, Req),
88 ----
89
90 .Push a resource with a custom host
91 [source,erlang]
92 ----
93 cowboy_req:push("/static/style.css", #{
94 <<"accept">> => <<"text/css">>
95 }, #{host => <<"cdn.example.org">>}, Req),
96 ----
97
98 == See also
99
100 link:man:cowboy_req(3)[cowboy_req(3)],
101 link:man:cowboy_req:inform(3)[cowboy_req:inform(3)],
102 link:man:cowboy_req:reply(3)[cowboy_req:reply(3)],
103 link:man:cowboy_req:stream_reply(3)[cowboy_req:stream_reply(3)]