aboutsummaryrefslogtreecommitdiffstats
path: root/doc/src/manual/gun_push.asciidoc
blob: e73c3b6d2518469b384fab29bdd00c047c70a547 (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
84
85
86
87
88
89
90
= gun_push(3)

== Name

gun_push - Server-initiated push

== Description

[source,erlang]
----
{gun_push, ConnPid, StreamRef, NewStreamRef, Method, URI, Headers}

ConnPid      :: pid()
StreamRef    :: reference()
NewStreamRef :: reference()
Method       :: binary()
URI          :: binary()
Headers      :: [{binary(), binary()}]
----

Server-initiated push.

This message informs the relevant process that the server
is pushing a resource related to the effective target URI
of the original request.

A server-initiated push message always precedes the response
to the original request.

This message will not be sent when using the HTTP/1.1 protocol
because it lacks the concept of server-initiated push.

== Elements

ConnPid::

The pid of the Gun connection process.

StreamRef::

Identifier of the stream for the original request.

NewStreamRef::

Identifier of the stream being pushed.

Method::

Method of the equivalent HTTP request.

URI::

URI of the resource being pushed.

Headers::

Headers of the equivalent HTTP request.

== Changelog

* *1.0*: Message introduced.

== Examples

.Receive a gun_push message in a gen_server
[source,erlang]
----
handle_info({gun_push, ConnPid, _StreamRef,
             _NewStreamRef, _Method, _URI, _Headers},
            State=#state{conn_pid=ConnPid}) ->
    %% Do something.
    {noreply, State}.
----

.Cancel an unwanted push
[source,erlang]
----
handle_info({gun_push, ConnPid, _StreamRef,
             NewStreamRef, _Method, _URI, _Headers},
            State=#state{conn_pid=ConnPid}) ->
    gun:cancel(ConnPid, NewStreamRef),
    {noreply, State}.
----

== See also

link:man:gun(3)[gun(3)],
link:man:gun:get(3)[gun:get(3)],
link:man:gun:cancel(3)[gun:cancel(3)],
link:man:gun_response(3)[gun_response(3)]