0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-15 04:30:25 +00:00
cowboy/doc/src/guide
Loïc Hoguin a45813c60f
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
..
architecture.asciidoc Convert the documentation to Asciidoc 2016-01-14 13:37:20 +01:00
book.asciidoc Various fixes and tweaks to the user guide 2017-01-02 14:46:19 +01:00
broken_clients.asciidoc Completely remove SPDY 2016-03-06 17:48:35 +01:00
constraints.asciidoc Use spaces in snippets in the guide 2016-09-14 18:51:11 +02:00
cookies.asciidoc Use spaces in snippets in the guide 2016-09-14 18:51:11 +02:00
cowboy.sty Minor documentation fixes 2016-08-30 14:18:14 +02:00
erlang_web.asciidoc Partial update of the user guide 2016-05-24 14:50:27 +02:00
flow_diagram.asciidoc Various fixes and tweaks to the user guide 2017-01-02 14:46:19 +01:00
getting_started.asciidoc Add templates as Erlang.mk plugin 2016-12-28 17:54:50 +01:00
handlers.asciidoc Various fixes and tweaks to the user guide 2017-01-02 14:46:19 +01:00
hooks.asciidoc Convert the documentation to Asciidoc 2016-01-14 13:37:20 +01:00
http_req_resp.png Remove the onrequest hook 2014-09-24 14:39:17 +03:00
http_req_resp.svg Remove the onrequest hook 2014-09-24 14:39:17 +03:00
introduction.asciidoc Welcome to 2017 2017-01-02 19:36:36 +01:00
listeners.asciidoc Various fixes and tweaks to the user guide 2017-01-02 14:46:19 +01:00
loop_handlers.asciidoc Allow passing options to sub protocols 2017-02-18 18:26:20 +01:00
middlewares.asciidoc Convert the documentation to Asciidoc 2016-01-14 13:37:20 +01:00
modern_web.asciidoc Partial update of the user guide 2016-05-24 14:50:27 +02:00
multipart.asciidoc Various fixes and tweaks to the user guide 2017-01-02 14:46:19 +01:00
overview.asciidoc Completely remove SPDY 2016-03-06 17:48:35 +01:00
req.asciidoc Use spaces in snippets in the guide 2016-09-14 18:51:11 +02:00
req_body.asciidoc Use spaces in snippets in the guide 2016-09-14 18:51:11 +02:00
resource_design.asciidoc Update the cowboy_rest manual 2016-12-28 15:17:43 +01:00
resp.asciidoc Use spaces in snippets in the guide 2016-09-14 18:51:11 +02:00
rest_cond.png Provide installable man pages 2014-07-06 13:10:35 +02:00
rest_cond.svg Provide installable man pages 2014-07-06 13:10:35 +02:00
rest_conneg.png Provide installable man pages 2014-07-06 13:10:35 +02:00
rest_conneg.svg Provide installable man pages 2014-07-06 13:10:35 +02:00
rest_delete.png Provide installable man pages 2014-07-06 13:10:35 +02:00
rest_delete.svg Provide installable man pages 2014-07-06 13:10:35 +02:00
rest_flowcharts.asciidoc Convert the documentation to Asciidoc 2016-01-14 13:37:20 +01:00
rest_get_head.png Provide installable man pages 2014-07-06 13:10:35 +02:00
rest_get_head.svg Provide installable man pages 2014-07-06 13:10:35 +02:00
rest_handlers.asciidoc Various fixes and tweaks to the user guide 2017-01-02 14:46:19 +01:00
rest_options.png Provide installable man pages 2014-07-06 13:10:35 +02:00
rest_options.svg Provide installable man pages 2014-07-06 13:10:35 +02:00
rest_principles.asciidoc Minor grammar improvements from Derek Brown 2016-01-15 16:16:56 +01:00
rest_put_post_patch.png Provide installable man pages 2014-07-06 13:10:35 +02:00
rest_put_post_patch.svg Provide installable man pages 2014-07-06 13:10:35 +02:00
rest_start.png Remove the REST known_content_type callback 2014-10-03 18:52:14 +03:00
rest_start.svg Remove the REST known_content_type callback 2014-10-03 18:52:14 +03:00
routing.asciidoc Update the routing chapter 2016-09-04 19:47:09 +02:00
static_files.asciidoc Minor updates to static files chapter 2016-09-02 14:55:40 +02:00
streams.asciidoc Various fixes and tweaks to the user guide 2017-01-02 14:46:19 +01:00
sub_protocols.asciidoc Allow passing options to sub protocols 2017-02-18 18:26:20 +01:00
ws_handlers.asciidoc Allow passing options to sub protocols 2017-02-18 18:26:20 +01:00
ws_protocol.asciidoc Allow passing options to sub protocols 2017-02-18 18:26:20 +01:00