mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-14 20:30:23 +00:00
Add cowboy_req:cast/2
Better than sending messages manually.
This commit is contained in:
parent
5cdf78fd57
commit
2e8fcb9a9e
6 changed files with 105 additions and 49 deletions
|
@ -90,6 +90,10 @@ Response:
|
|||
* link:man:cowboy_req:stream_trailers(3)[cowboy_req:stream_trailers(3)] - Send the response trailers
|
||||
* link:man:cowboy_req:push(3)[cowboy_req:push(3)] - Push a resource to the client
|
||||
|
||||
Stream handlers:
|
||||
|
||||
* link:man:cowboy_req:cast(3)[cowboy_req:cast(3)] - Cast a stream handler event
|
||||
|
||||
== Types
|
||||
|
||||
=== push_opts()
|
||||
|
|
64
doc/src/manual/cowboy_req.cast.asciidoc
Normal file
64
doc/src/manual/cowboy_req.cast.asciidoc
Normal file
|
@ -0,0 +1,64 @@
|
|||
= 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
|
||||
|
||||
.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)]
|
|
@ -277,9 +277,8 @@ relevant option's documentation for details.
|
|||
|
||||
Cowboy will forward all messages sent to the stream to
|
||||
the `info/3` callback. To send a message to a stream,
|
||||
send a message to the connection process with the form
|
||||
`{{Pid, StreamID}, Msg}`. The connection process will
|
||||
then forward `Msg` to the stream handlers.
|
||||
the function link:man:cowboy_req:cast(3)[cowboy_req:cast(3)]
|
||||
can be used.
|
||||
|
||||
Cowboy will also forward the exit signals for the
|
||||
processes that the stream spawned.
|
||||
|
@ -403,4 +402,5 @@ tuple.
|
|||
|
||||
link:man:cowboy(7)[cowboy(7)],
|
||||
link:man:cowboy_http(3)[cowboy_http(3)],
|
||||
link:man:cowboy_http2(3)[cowboy_http2(3)]
|
||||
link:man:cowboy_http2(3)[cowboy_http2(3)],
|
||||
link:man:cowboy_req:cast(3)[cowboy_req:cast(3)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue