| 1 |
= cowboy_req:cast(3) |
| 2 |
|
| 3 |
== Name |
| 4 |
|
| 5 |
cowboy_req:cast - Cast a stream handler event |
| 6 |
|
| 7 |
== Description |
| 8 |
|
| 9 |
[source,erlang] |
| 10 |
---- |
| 11 |
cast(Event :: any(), Req :: cowboy_req:req()) -> ok |
| 12 |
---- |
| 13 |
|
| 14 |
Cast a stream handler event. |
| 15 |
|
| 16 |
The event will be passed to stream handlers through the |
| 17 |
`info/3` callback. |
| 18 |
|
| 19 |
== Arguments |
| 20 |
|
| 21 |
Event:: |
| 22 |
|
| 23 |
The event to be sent to stream handlers. |
| 24 |
|
| 25 |
Req:: |
| 26 |
|
| 27 |
The Req object. |
| 28 |
|
| 29 |
== Return value |
| 30 |
|
| 31 |
The atom `ok` is always returned. It can be safely ignored. |
| 32 |
|
| 33 |
== Changelog |
| 34 |
|
| 35 |
* *2.7*: Function introduced. |
| 36 |
|
| 37 |
== Examples |
| 38 |
|
| 39 |
.Read the body using auto mode |
| 40 |
[source,erlang] |
| 41 |
---- |
| 42 |
read_body_auto_async(Req) -> |
| 43 |
read_body_auto_async(Req, make_ref(), <<>>). |
| 44 |
|
| 45 |
read_body_auto_async(Req, Ref, Acc) -> |
| 46 |
cowboy_req:cast({read_body, self(), Ref, auto, infinity}, Req), |
| 47 |
receive |
| 48 |
{request_body, Ref, nofin, Data} -> |
| 49 |
read_body_auto_async(Req, Ref, <<Acc/binary, Data/binary>>); |
| 50 |
{request_body, Ref, fin, _BodyLen, Data} -> |
| 51 |
{ok, <<Acc/binary, Data/binary>>, Req} |
| 52 |
end. |
| 53 |
---- |
| 54 |
|
| 55 |
.Increase the HTTP/1.1 idle timeout |
| 56 |
[source,erlang] |
| 57 |
---- |
| 58 |
cowboy_req:cast({set_options, #{ |
| 59 |
idle_timeout => 3600000 |
| 60 |
}}, Req). |
| 61 |
---- |
| 62 |
|
| 63 |
.Add user data to metrics |
| 64 |
---- |
| 65 |
cowboy_req:cast({set_options, #{ |
| 66 |
metrics_user_data => #{handler => ?MODULE} |
| 67 |
}}, Req). |
| 68 |
---- |
| 69 |
|
| 70 |
.Enable compression buffering |
| 71 |
---- |
| 72 |
cowboy_req:cast({set_options, #{ |
| 73 |
compress_buffering => true |
| 74 |
}}, Req). |
| 75 |
---- |
| 76 |
|
| 77 |
== See also |
| 78 |
|
| 79 |
link:man:cowboy_req(3)[cowboy_req(3)], |
| 80 |
link:man:cowboy_stream(3)[cowboy_stream(3)] |