2016-01-14 13:35:25 +01:00
|
|
|
= cowboy_websocket(3)
|
|
|
|
|
|
|
|
== Name
|
|
|
|
|
2016-12-22 18:13:25 +01:00
|
|
|
cowboy_websocket - Websocket
|
2016-01-14 13:35:25 +01:00
|
|
|
|
|
|
|
== Description
|
2014-07-06 13:10:35 +02:00
|
|
|
|
2016-12-22 18:13:25 +01:00
|
|
|
The module `cowboy_websocket` implements Websocket
|
|
|
|
as a Ranch protocol. It also defines a callback interface
|
|
|
|
for handling Websocket connections.
|
2014-07-06 13:10:35 +02:00
|
|
|
|
2016-12-22 18:13:25 +01:00
|
|
|
== Callbacks
|
2014-07-06 13:10:35 +02:00
|
|
|
|
2016-12-22 18:13:25 +01:00
|
|
|
Websocket handlers must implement the following callback
|
|
|
|
interface:
|
2014-07-06 13:10:35 +02:00
|
|
|
|
2016-12-22 18:13:25 +01:00
|
|
|
[source,erlang]
|
|
|
|
----
|
|
|
|
init(Req, State)
|
|
|
|
-> {cowboy_websocket, Req, State}
|
Allow passing options to sub protocols
Before this commit we had an issue where configuring a
Websocket connection was simply not possible without
doing magic, adding callbacks or extra return values.
The init/2 function only allowed setting hibernate
and timeout options.
After this commit, when switching to a different
type of handler you can either return
{module, Req, State}
or
{module, Req, State, Opts}
where Opts is any value (as far as the sub protocol
interface is concerned) and is ultimately checked
by the custom handlers.
A large protocol like Websocket would accept only
a map there, with many different options, while a
small interface like loop handlers would allow
passing hibernate and nothing else.
For Websocket, hibernate must be set from the
websocket_init/1 callback, because init/2 executes
in a separate process.
Sub protocols now have two callbacks: one with the
Opts value, one without.
The loop handler code was largely reworked and
simplified. It does not need to manage a timeout
or read from the socket anymore, it's the job of
the protocol code. A lot of unnecessary stuff was
therefore removed.
Websocket compression must now be enabled from
the handler options instead of per listener. This
means that a project can have two separate Websocket
handlers with different options. Compression is
still disabled by default, and the idle_timeout
value was changed from inifnity to 60000 (60 seconds),
as that's safer and is also a good value for mobile
devices.
2017-02-18 18:26:20 +01:00
|
|
|
| {cowboy_websocket, Req, State, Opts}
|
2016-12-22 18:13:25 +01:00
|
|
|
|
|
|
|
websocket_init(State) -> CallResult %% optional
|
|
|
|
websocket_handle(InFrame, State) -> CallResult
|
|
|
|
websocket_info(Info, State) -> CallResult
|
|
|
|
|
2017-09-04 14:33:44 +02:00
|
|
|
terminate(Reason, PartialReq, State) -> ok %% optional
|
2016-12-22 18:13:25 +01:00
|
|
|
|
|
|
|
Req :: cowboy_req:req()
|
2017-09-04 14:33:44 +02:00
|
|
|
PartialReq :: map()
|
2016-12-22 18:13:25 +01:00
|
|
|
State :: any()
|
Allow passing options to sub protocols
Before this commit we had an issue where configuring a
Websocket connection was simply not possible without
doing magic, adding callbacks or extra return values.
The init/2 function only allowed setting hibernate
and timeout options.
After this commit, when switching to a different
type of handler you can either return
{module, Req, State}
or
{module, Req, State, Opts}
where Opts is any value (as far as the sub protocol
interface is concerned) and is ultimately checked
by the custom handlers.
A large protocol like Websocket would accept only
a map there, with many different options, while a
small interface like loop handlers would allow
passing hibernate and nothing else.
For Websocket, hibernate must be set from the
websocket_init/1 callback, because init/2 executes
in a separate process.
Sub protocols now have two callbacks: one with the
Opts value, one without.
The loop handler code was largely reworked and
simplified. It does not need to manage a timeout
or read from the socket anymore, it's the job of
the protocol code. A lot of unnecessary stuff was
therefore removed.
Websocket compression must now be enabled from
the handler options instead of per listener. This
means that a project can have two separate Websocket
handlers with different options. Compression is
still disabled by default, and the idle_timeout
value was changed from inifnity to 60000 (60 seconds),
as that's safer and is also a good value for mobile
devices.
2017-02-18 18:26:20 +01:00
|
|
|
Opts :: cowboy_websocket:opts()
|
2018-06-26 10:59:22 +02:00
|
|
|
InFrame :: ping | pong | {text | binary | ping | pong, binary()}
|
2016-12-22 18:13:25 +01:00
|
|
|
Info :: any()
|
|
|
|
|
2019-10-06 16:51:27 +02:00
|
|
|
CallResult :: {commands(), State}
|
|
|
|
| {commands(), State, hibernate}
|
|
|
|
| Deprecated
|
|
|
|
|
|
|
|
Deprecated :: {ok, State}
|
2016-12-22 18:13:25 +01:00
|
|
|
| {ok, State, hibernate}
|
|
|
|
| {reply, OutFrame | [OutFrame], State}
|
|
|
|
| {reply, OutFrame | [OutFrame], State, hibernate}
|
|
|
|
| {stop, State}
|
2019-10-06 16:51:27 +02:00
|
|
|
OutFrame :: cow_ws:frame() %% see types below
|
2016-12-22 18:13:25 +01:00
|
|
|
|
|
|
|
Reason :: normal | stop | timeout
|
|
|
|
| remote | {remote, cow_ws:close_code(), binary()}
|
|
|
|
| {error, badencoding | badframe | closed | atom()}
|
|
|
|
| {crash, error | exit | throw, any()}
|
|
|
|
----
|
|
|
|
|
|
|
|
The `init/2` callback is common to all handlers. To upgrade
|
|
|
|
the connection to Websocket, it must return `cowboy_websocket`
|
|
|
|
as the first element of the tuple.
|
|
|
|
|
|
|
|
Any operation requiring the HTTP request must be done in the
|
|
|
|
`init/2` function, as the Req object will not be available
|
|
|
|
after it returns. Websocket sub-protocol selection should
|
|
|
|
therefore be done in this function.
|
2014-07-06 13:10:35 +02:00
|
|
|
|
2016-12-22 18:13:25 +01:00
|
|
|
The optional `websocket_init/1` callback will be called once
|
|
|
|
the connection has been upgraded to Websocket. It can be used
|
|
|
|
to perform any required initialization of the handler.
|
2014-07-06 13:10:35 +02:00
|
|
|
|
2016-12-22 18:13:25 +01:00
|
|
|
Note that the `init/2` function does not run in the same
|
|
|
|
process as the Websocket callbacks. Any Websocket-specific
|
|
|
|
initialization must be done in `websocket_init/1`.
|
2014-09-30 20:12:13 +03:00
|
|
|
|
2016-12-22 18:13:25 +01:00
|
|
|
The `websocket_handle/2` callback will be called for every
|
|
|
|
frame received. The `websocket_info/2` callback will be
|
|
|
|
called for every Erlang message received.
|
|
|
|
|
|
|
|
All three Websocket callbacks may send one or more frames
|
2019-10-06 16:51:27 +02:00
|
|
|
back to the client, including close frames to terminate
|
|
|
|
the connection; enable/disable active mode; enable/disable
|
|
|
|
compression for subsequent frames; or change Websocket options.
|
2016-12-22 18:13:25 +01:00
|
|
|
|
|
|
|
The optional `terminate/3` callback will ultimately be called
|
|
|
|
with the reason for the termination of the connection. This
|
2017-09-04 14:33:44 +02:00
|
|
|
callback is common to all handlers. Note that Websocket will
|
|
|
|
not provide the full Req object by default, to save memory.
|
2016-12-22 18:13:25 +01:00
|
|
|
|
|
|
|
Cowboy will terminate the process right after closing the
|
|
|
|
Websocket connection. This means that there is no need to
|
|
|
|
perform any cleanup in the `terminate/3` callback.
|
|
|
|
|
|
|
|
The following terminate reasons are defined for Websocket
|
|
|
|
connections:
|
2014-09-30 20:12:13 +03:00
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
normal::
|
2016-12-22 18:13:25 +01:00
|
|
|
The connection was closed normally before establishing a Websocket
|
|
|
|
connection. This typically happens if an `ok` tuple is returned
|
|
|
|
from the `init/2` callback.
|
2014-09-30 20:12:13 +03:00
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
remote::
|
2016-12-22 18:13:25 +01:00
|
|
|
The remote endpoint closed the connection without giving any
|
|
|
|
further details.
|
2014-09-30 20:12:13 +03:00
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
{remote, Code, Payload}::
|
2016-12-22 18:13:25 +01:00
|
|
|
The remote endpoint closed the connection with the given
|
|
|
|
`Code` and `Payload` as the reason.
|
2014-09-30 20:12:13 +03:00
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
stop::
|
2016-12-22 18:13:25 +01:00
|
|
|
The handler requested to close the connection, either by returning
|
|
|
|
a `stop` tuple or by sending a `close` frame.
|
2014-09-30 20:12:13 +03:00
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
timeout::
|
2016-12-22 18:13:25 +01:00
|
|
|
The connection has been closed due to inactivity. The timeout
|
|
|
|
value can be configured from `init/2`.
|
2014-09-30 20:12:13 +03:00
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
{crash, Class, Reason}::
|
2016-12-22 18:13:25 +01:00
|
|
|
A crash occurred in the handler. `Class` and `Reason` can be
|
2019-12-31 15:10:38 +01:00
|
|
|
used to obtain more information about the crash.
|
2014-09-30 20:12:13 +03:00
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
{error, badencoding}::
|
2016-12-22 18:13:25 +01:00
|
|
|
A text frame was sent by the client with invalid encoding. All
|
|
|
|
text frames must be valid UTF-8.
|
2014-09-30 20:12:13 +03:00
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
{error, badframe}::
|
2016-12-22 18:13:25 +01:00
|
|
|
A protocol error has been detected.
|
2014-09-30 20:12:13 +03:00
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
{error, closed}::
|
2016-12-22 18:13:25 +01:00
|
|
|
The socket has been closed brutally without a close frame being
|
|
|
|
received first.
|
2014-09-30 20:12:13 +03:00
|
|
|
|
2016-01-14 13:35:25 +01:00
|
|
|
{error, Reason}::
|
2021-08-29 22:32:15 +08:00
|
|
|
A socket error occurred.
|
2014-09-30 20:12:13 +03:00
|
|
|
|
Allow passing options to sub protocols
Before this commit we had an issue where configuring a
Websocket connection was simply not possible without
doing magic, adding callbacks or extra return values.
The init/2 function only allowed setting hibernate
and timeout options.
After this commit, when switching to a different
type of handler you can either return
{module, Req, State}
or
{module, Req, State, Opts}
where Opts is any value (as far as the sub protocol
interface is concerned) and is ultimately checked
by the custom handlers.
A large protocol like Websocket would accept only
a map there, with many different options, while a
small interface like loop handlers would allow
passing hibernate and nothing else.
For Websocket, hibernate must be set from the
websocket_init/1 callback, because init/2 executes
in a separate process.
Sub protocols now have two callbacks: one with the
Opts value, one without.
The loop handler code was largely reworked and
simplified. It does not need to manage a timeout
or read from the socket anymore, it's the job of
the protocol code. A lot of unnecessary stuff was
therefore removed.
Websocket compression must now be enabled from
the handler options instead of per listener. This
means that a project can have two separate Websocket
handlers with different options. Compression is
still disabled by default, and the idle_timeout
value was changed from inifnity to 60000 (60 seconds),
as that's safer and is also a good value for mobile
devices.
2017-02-18 18:26:20 +01:00
|
|
|
== Types
|
|
|
|
|
2019-10-06 16:51:27 +02:00
|
|
|
=== commands()
|
|
|
|
|
|
|
|
[source,erlang]
|
|
|
|
----
|
|
|
|
commands() :: [Command]
|
|
|
|
|
|
|
|
Command :: {active, boolean()}
|
|
|
|
| {deflate, boolean()}
|
|
|
|
| {set_options, #{idle_timeout => timeout()}}
|
2019-10-10 11:33:35 +02:00
|
|
|
| {shutdown_reason, any()}
|
2019-10-06 16:51:27 +02:00
|
|
|
| Frame :: cow_ws:frame()
|
|
|
|
----
|
|
|
|
|
|
|
|
Commands that may be returned from Websocket callbacks.
|
|
|
|
|
|
|
|
The following commands are defined:
|
|
|
|
|
|
|
|
active::
|
|
|
|
|
|
|
|
Whether to disable or enable reading from the socket. This
|
|
|
|
can be used to apply flow control to a Websocket connection.
|
|
|
|
|
|
|
|
deflate::
|
|
|
|
|
|
|
|
Whether the subsequent frames should be compressed. Has no
|
|
|
|
effect on connections that did not negotiate compression.
|
|
|
|
|
|
|
|
set_options::
|
|
|
|
|
|
|
|
Set Websocket options. Currently only the option `idle_timeout`
|
|
|
|
may be updated from a Websocket handler.
|
|
|
|
|
2019-10-10 11:33:35 +02:00
|
|
|
shutdown_reason::
|
|
|
|
|
|
|
|
Change the shutdown reason. The Websocket process will exit
|
|
|
|
with reason `normal` by default. This command can be used to
|
|
|
|
exit with reason `{shutdown, ShutdownReason}` under normal
|
|
|
|
conditions. This command has no effect when the Websocket
|
|
|
|
process exits abnormally, for example following a crash in a
|
|
|
|
handler callback.
|
|
|
|
|
2019-10-06 16:51:27 +02:00
|
|
|
Frame::
|
|
|
|
|
|
|
|
Send the corresponding Websocket frame.
|
|
|
|
|
2018-06-06 18:03:01 +02:00
|
|
|
=== cow_ws:frame()
|
2017-10-02 18:06:06 +02:00
|
|
|
|
|
|
|
[source,erlang]
|
|
|
|
----
|
|
|
|
frame() :: {text, iodata()}
|
|
|
|
| {binary, iodata()}
|
|
|
|
| ping | {ping, iodata()}
|
|
|
|
| pong | {pong, iodata()}
|
|
|
|
| close | {close, iodata()} | {close, close_code(), iodata()}
|
|
|
|
|
|
|
|
close_code() :: 1000..1003 | 1006..1011 | 3000..4999
|
|
|
|
----
|
|
|
|
|
|
|
|
Websocket frames that can be sent as a response.
|
|
|
|
|
|
|
|
Note that there is no need to send pong frames back as
|
|
|
|
Cowboy does it automatically for you.
|
|
|
|
|
Allow passing options to sub protocols
Before this commit we had an issue where configuring a
Websocket connection was simply not possible without
doing magic, adding callbacks or extra return values.
The init/2 function only allowed setting hibernate
and timeout options.
After this commit, when switching to a different
type of handler you can either return
{module, Req, State}
or
{module, Req, State, Opts}
where Opts is any value (as far as the sub protocol
interface is concerned) and is ultimately checked
by the custom handlers.
A large protocol like Websocket would accept only
a map there, with many different options, while a
small interface like loop handlers would allow
passing hibernate and nothing else.
For Websocket, hibernate must be set from the
websocket_init/1 callback, because init/2 executes
in a separate process.
Sub protocols now have two callbacks: one with the
Opts value, one without.
The loop handler code was largely reworked and
simplified. It does not need to manage a timeout
or read from the socket anymore, it's the job of
the protocol code. A lot of unnecessary stuff was
therefore removed.
Websocket compression must now be enabled from
the handler options instead of per listener. This
means that a project can have two separate Websocket
handlers with different options. Compression is
still disabled by default, and the idle_timeout
value was changed from inifnity to 60000 (60 seconds),
as that's safer and is also a good value for mobile
devices.
2017-02-18 18:26:20 +01:00
|
|
|
=== opts()
|
|
|
|
|
|
|
|
[source,erlang]
|
|
|
|
----
|
|
|
|
opts() :: #{
|
2019-12-04 11:17:34 +01:00
|
|
|
active_n => pos_integer(),
|
2019-10-05 17:32:50 +02:00
|
|
|
compress => boolean(),
|
|
|
|
deflate_opts => cow_ws:deflate_opts()
|
|
|
|
idle_timeout => timeout(),
|
2017-08-25 12:08:26 +03:00
|
|
|
max_frame_size => non_neg_integer() | infinity,
|
2019-10-05 17:32:50 +02:00
|
|
|
req_filter => fun((cowboy_req:req()) -> map()),
|
|
|
|
validate_utf8 => boolean()
|
Allow passing options to sub protocols
Before this commit we had an issue where configuring a
Websocket connection was simply not possible without
doing magic, adding callbacks or extra return values.
The init/2 function only allowed setting hibernate
and timeout options.
After this commit, when switching to a different
type of handler you can either return
{module, Req, State}
or
{module, Req, State, Opts}
where Opts is any value (as far as the sub protocol
interface is concerned) and is ultimately checked
by the custom handlers.
A large protocol like Websocket would accept only
a map there, with many different options, while a
small interface like loop handlers would allow
passing hibernate and nothing else.
For Websocket, hibernate must be set from the
websocket_init/1 callback, because init/2 executes
in a separate process.
Sub protocols now have two callbacks: one with the
Opts value, one without.
The loop handler code was largely reworked and
simplified. It does not need to manage a timeout
or read from the socket anymore, it's the job of
the protocol code. A lot of unnecessary stuff was
therefore removed.
Websocket compression must now be enabled from
the handler options instead of per listener. This
means that a project can have two separate Websocket
handlers with different options. Compression is
still disabled by default, and the idle_timeout
value was changed from inifnity to 60000 (60 seconds),
as that's safer and is also a good value for mobile
devices.
2017-02-18 18:26:20 +01:00
|
|
|
}
|
|
|
|
----
|
|
|
|
|
|
|
|
Websocket handler options.
|
|
|
|
|
|
|
|
This configuration is passed to Cowboy from the `init/2`
|
|
|
|
function:
|
|
|
|
|
|
|
|
[source,erlang]
|
|
|
|
----
|
|
|
|
init(Req, State) ->
|
|
|
|
Opts = #{compress => true},
|
|
|
|
{cowboy_websocket, Req, State, Opts}.
|
|
|
|
----
|
|
|
|
|
|
|
|
The default value is given next to the option name:
|
|
|
|
|
2019-12-04 11:17:34 +01:00
|
|
|
active_n (100)::
|
|
|
|
|
|
|
|
The number of packets Cowboy will request from the socket at once.
|
|
|
|
This can be used to tweak the performance of the server. Higher
|
|
|
|
values reduce the number of times Cowboy need to request more
|
|
|
|
packets from the port driver at the expense of potentially
|
|
|
|
higher memory being used.
|
|
|
|
+
|
|
|
|
This option does not apply to Websocket over HTTP/2.
|
|
|
|
|
Allow passing options to sub protocols
Before this commit we had an issue where configuring a
Websocket connection was simply not possible without
doing magic, adding callbacks or extra return values.
The init/2 function only allowed setting hibernate
and timeout options.
After this commit, when switching to a different
type of handler you can either return
{module, Req, State}
or
{module, Req, State, Opts}
where Opts is any value (as far as the sub protocol
interface is concerned) and is ultimately checked
by the custom handlers.
A large protocol like Websocket would accept only
a map there, with many different options, while a
small interface like loop handlers would allow
passing hibernate and nothing else.
For Websocket, hibernate must be set from the
websocket_init/1 callback, because init/2 executes
in a separate process.
Sub protocols now have two callbacks: one with the
Opts value, one without.
The loop handler code was largely reworked and
simplified. It does not need to manage a timeout
or read from the socket anymore, it's the job of
the protocol code. A lot of unnecessary stuff was
therefore removed.
Websocket compression must now be enabled from
the handler options instead of per listener. This
means that a project can have two separate Websocket
handlers with different options. Compression is
still disabled by default, and the idle_timeout
value was changed from inifnity to 60000 (60 seconds),
as that's safer and is also a good value for mobile
devices.
2017-02-18 18:26:20 +01:00
|
|
|
compress (false)::
|
2018-11-12 18:12:44 +01:00
|
|
|
|
|
|
|
Whether to enable the Websocket frame compression
|
|
|
|
extension. Frames will only be compressed for the
|
|
|
|
clients that support this extension.
|
|
|
|
|
|
|
|
deflate_opts (#{})::
|
|
|
|
|
|
|
|
Configuration for the permessage-deflate Websocket
|
|
|
|
extension. Allows configuring both the negotiated
|
|
|
|
options and the zlib compression options. The
|
|
|
|
defaults optimize the compression at the expense
|
|
|
|
of some memory and CPU.
|
Allow passing options to sub protocols
Before this commit we had an issue where configuring a
Websocket connection was simply not possible without
doing magic, adding callbacks or extra return values.
The init/2 function only allowed setting hibernate
and timeout options.
After this commit, when switching to a different
type of handler you can either return
{module, Req, State}
or
{module, Req, State, Opts}
where Opts is any value (as far as the sub protocol
interface is concerned) and is ultimately checked
by the custom handlers.
A large protocol like Websocket would accept only
a map there, with many different options, while a
small interface like loop handlers would allow
passing hibernate and nothing else.
For Websocket, hibernate must be set from the
websocket_init/1 callback, because init/2 executes
in a separate process.
Sub protocols now have two callbacks: one with the
Opts value, one without.
The loop handler code was largely reworked and
simplified. It does not need to manage a timeout
or read from the socket anymore, it's the job of
the protocol code. A lot of unnecessary stuff was
therefore removed.
Websocket compression must now be enabled from
the handler options instead of per listener. This
means that a project can have two separate Websocket
handlers with different options. Compression is
still disabled by default, and the idle_timeout
value was changed from inifnity to 60000 (60 seconds),
as that's safer and is also a good value for mobile
devices.
2017-02-18 18:26:20 +01:00
|
|
|
|
|
|
|
idle_timeout (60000)::
|
2018-11-12 18:12:44 +01:00
|
|
|
|
|
|
|
Time in milliseconds that Cowboy will keep the
|
|
|
|
connection open without receiving anything from
|
|
|
|
the client.
|
2019-10-07 12:04:39 +02:00
|
|
|
+
|
|
|
|
This option can be updated at any time using the
|
|
|
|
`set_options` command.
|
Allow passing options to sub protocols
Before this commit we had an issue where configuring a
Websocket connection was simply not possible without
doing magic, adding callbacks or extra return values.
The init/2 function only allowed setting hibernate
and timeout options.
After this commit, when switching to a different
type of handler you can either return
{module, Req, State}
or
{module, Req, State, Opts}
where Opts is any value (as far as the sub protocol
interface is concerned) and is ultimately checked
by the custom handlers.
A large protocol like Websocket would accept only
a map there, with many different options, while a
small interface like loop handlers would allow
passing hibernate and nothing else.
For Websocket, hibernate must be set from the
websocket_init/1 callback, because init/2 executes
in a separate process.
Sub protocols now have two callbacks: one with the
Opts value, one without.
The loop handler code was largely reworked and
simplified. It does not need to manage a timeout
or read from the socket anymore, it's the job of
the protocol code. A lot of unnecessary stuff was
therefore removed.
Websocket compression must now be enabled from
the handler options instead of per listener. This
means that a project can have two separate Websocket
handlers with different options. Compression is
still disabled by default, and the idle_timeout
value was changed from inifnity to 60000 (60 seconds),
as that's safer and is also a good value for mobile
devices.
2017-02-18 18:26:20 +01:00
|
|
|
|
2017-08-25 12:08:26 +03:00
|
|
|
max_frame_size (infinity)::
|
2018-11-12 18:12:44 +01:00
|
|
|
|
2019-09-06 11:50:58 +02:00
|
|
|
Maximum frame size in bytes allowed by this Websocket
|
2018-11-12 18:12:44 +01:00
|
|
|
handler. Cowboy will close the connection when
|
|
|
|
a client attempts to send a frame that goes over
|
|
|
|
this limit. For fragmented frames this applies
|
|
|
|
to the size of the reconstituted frame.
|
2017-08-25 12:08:26 +03:00
|
|
|
|
2017-05-28 19:04:16 +02:00
|
|
|
req_filter::
|
2018-11-12 18:12:44 +01:00
|
|
|
|
|
|
|
A function applied to the Req to compact it and
|
|
|
|
only keep required information. The Req is only
|
|
|
|
given back in the `terminate/3` callback. By default
|
|
|
|
it keeps the method, version, URI components and peer
|
|
|
|
information.
|
2017-05-28 19:04:16 +02:00
|
|
|
|
2019-10-05 17:32:50 +02:00
|
|
|
validate_utf8 (true)::
|
|
|
|
|
|
|
|
Whether Cowboy should verify that the payload of
|
|
|
|
`text` and `close` frames is valid UTF-8. This is
|
|
|
|
required by the protocol specification but in some
|
|
|
|
cases it may be more interesting to disable it in
|
|
|
|
order to save resources.
|
|
|
|
+
|
|
|
|
Note that `binary` frames do not have this UTF-8
|
|
|
|
requirement and are what should be used under
|
|
|
|
normal circumstances if necessary.
|
|
|
|
|
2016-12-22 18:13:25 +01:00
|
|
|
== Changelog
|
2014-09-30 20:12:13 +03:00
|
|
|
|
2024-01-23 15:29:41 +01:00
|
|
|
* *2.11*: Websocket over HTTP/2 is now considered stable.
|
2024-01-08 11:44:34 +01:00
|
|
|
* *2.11*: HTTP/1.1 Websocket no longer traps exits by default.
|
2019-12-04 11:17:34 +01:00
|
|
|
* *2.8*: The `active_n` option was added.
|
2019-10-10 11:33:35 +02:00
|
|
|
* *2.7*: The commands based interface has been documented.
|
|
|
|
The old interface is now deprecated.
|
|
|
|
* *2.7*: The command `shutdown_reason` was introduced.
|
2019-10-05 17:32:50 +02:00
|
|
|
* *2.7*: The option `validate_utf8` has been added.
|
2018-11-12 18:12:44 +01:00
|
|
|
* *2.6*: Deflate options can now be configured via `deflate_opts`.
|
2016-12-22 18:13:25 +01:00
|
|
|
* *2.0*: The Req object is no longer passed to Websocket callbacks.
|
|
|
|
* *2.0*: The callback `websocket_terminate/3` was removed in favor of `terminate/3`.
|
|
|
|
* *1.0*: Protocol introduced.
|
2014-09-30 20:12:13 +03:00
|
|
|
|
2016-12-22 18:13:25 +01:00
|
|
|
== See also
|
2014-09-30 20:12:13 +03:00
|
|
|
|
2016-12-22 18:13:25 +01:00
|
|
|
link:man:cowboy(7)[cowboy(7)],
|
2016-12-23 17:20:54 +01:00
|
|
|
link:man:cowboy_handler(3)[cowboy_handler(3)],
|
2016-12-22 18:13:25 +01:00
|
|
|
link:man:cowboy_http(3)[cowboy_http(3)],
|
|
|
|
link:man:cowboy_http2(3)[cowboy_http2(3)]
|