aboutsummaryrefslogtreecommitdiffstats
path: root/doc/src/manual/cowboy_req.cast.asciidoc
blob: b12157fac11f59ead19f0fdc35be6951058a0a74 (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
= cowboy_req:cast(3)

== Name

cowboy_req:cast - Cast a stream handler event

== Description

[source,erlang]
----
cast(Event :: any(), Req :: cowboy_req:req()) -> ok
----

Cast a stream handler event.

The event will be passed to stream handlers through the
`info/3` callback.

== Arguments

Event::

The event to be sent to stream handlers.

Req::

The Req object.

== Return value

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

== Changelog

* *2.7*: Function introduced.

== Examples

.Read the body using auto mode
[source,erlang]
----
read_body_auto_async(Req) ->
    read_body_auto_async(Req, make_ref(), <<>>).

read_body_auto_async(Req, Ref, Acc) ->
    cowboy_req:cast({read_body, self(), Ref, auto, infinity}, Req),
    receive
        {request_body, Ref, nofin, Data} ->
            read_body_auto_async(Req, Ref, <<Acc/binary, Data/binary>>);
        {request_body, Ref, fin, _BodyLen, Data} ->
            {ok, <<Acc/binary, Data/binary>>, Req}
    end.
----

.Increase the HTTP/1.1 idle timeout
[source,erlang]
----
cowboy_req:cast({set_options, #{
    idle_timeout => 3600000
}}, Req).
----

.Add user data to metrics
----
cowboy_req:cast({set_options, #{
    metrics_user_data => #{handler => ?MODULE}
}}, Req).
----

.Enable compression buffering
----
cowboy_req:cast({set_options, #{
    compress_buffering => true
}}, Req).
----

== See also

link:man:cowboy_req(3)[cowboy_req(3)],
link:man:cowboy_stream(3)[cowboy_stream(3)]