0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-14 12:20:24 +00:00
Small, fast, modern HTTP server for Erlang/OTP.
Find a file
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
doc/src Allow passing options to sub protocols 2017-02-18 18:26:20 +01:00
ebin Add experimental cowboy_compress_h stream handler 2017-01-22 10:50:39 +01:00
examples Allow passing options to sub protocols 2017-02-18 18:26:20 +01:00
src Allow passing options to sub protocols 2017-02-18 18:26:20 +01:00
test Allow passing options to sub protocols 2017-02-18 18:26:20 +01:00
.gitattributes Convert the documentation to Asciidoc 2016-01-14 13:37:20 +01:00
.gitignore gitignore: add examples/ dependency files 2016-05-25 12:54:12 +02:00
CHANGELOG.md Update CHANGELOG 2014-10-04 15:50:53 +03:00
CONTRIBUTING.asciidoc Update CONTRIBUTING 2015-11-16 18:55:53 +01:00
erlang.mk Update Erlang.mk 2017-01-02 19:28:48 +01:00
LICENSE Welcome to 2017 2017-01-02 19:36:36 +01:00
Makefile Erlang/OTP 19.2.2 and 18.3.4.5 2017-02-05 15:10:26 +01:00
plugins.mk Allow passing options to sub protocols 2017-02-18 18:26:20 +01:00
README.asciidoc Update README 2017-01-02 19:28:11 +01:00
rebar.config Update rebar.config 2017-01-03 12:15:42 +01:00

= Cowboy

Cowboy is a small, fast and modern HTTP server for Erlang/OTP.

== Goals

Cowboy aims to provide a *complete* HTTP stack in a *small* code base.
It is optimized for *low latency* and *low memory usage*, in part
because it uses *binary strings*.

Cowboy provides *routing* capabilities, selectively dispatching requests
to handlers written in Erlang.

Because it uses Ranch for managing connections, Cowboy can easily be
*embedded* in any other application.

Cowboy is *clean* and *well tested* Erlang code.

== Online documentation

* http://ninenines.eu/docs/en/cowboy/2.0/guide[User guide]
* http://ninenines.eu/docs/en/cowboy/2.0/manual[Function reference]

== Offline documentation

* While still online, run `make docs`
* User guide available in `doc/` in PDF and HTML formats
* Function reference man pages available in `doc/man3/` and `doc/man7/`
* Run `make install-docs` to install man pages on your system
* Full documentation in Asciidoc available in `doc/src/`
* Examples available in `examples/`

== Getting help

* Official IRC Channel: #ninenines on irc.freenode.net
* https://github.com/ninenines/cowboy/issues[Issues tracker]
* http://ninenines.eu/services[Commercial Support]