mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-15 20:50:24 +00:00

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.
78 lines
2.2 KiB
Text
78 lines
2.2 KiB
Text
= cowboy(7)
|
|
|
|
== Name
|
|
|
|
cowboy - Small, fast, modern HTTP server for Erlang/OTP
|
|
|
|
== Description
|
|
|
|
Cowboy is an HTTP server for Erlang/OTP with support for the
|
|
HTTP/1.1, HTTP/2 and Websocket protocols.
|
|
|
|
Cowboy aims to provide a complete HTTP stack. This includes
|
|
the implementation of the HTTP RFCs but also any directly
|
|
related standards, like Websocket or Server-Sent Events.
|
|
|
|
== Modules
|
|
|
|
Functions:
|
|
|
|
* link:man:cowboy(3)[cowboy(3)] - Listener management
|
|
* link:man:cowboy_req(3)[cowboy_req(3)] - Request and response
|
|
* link:man:cowboy_router(3)[cowboy_router(3)] - Router
|
|
|
|
// @todo What about cowboy_constraints?
|
|
|
|
Protocols:
|
|
|
|
* link:man:cowboy_http(3)[cowboy_http(3)] - HTTP/1.1
|
|
* link:man:cowboy_http2(3)[cowboy_http2(3)] - HTTP/2
|
|
* link:man:cowboy_websocket(3)[cowboy_websocket(3)] - Websocket
|
|
|
|
Handlers:
|
|
|
|
* link:man:cowboy_static(3)[cowboy_static(3)] - Static file handler
|
|
|
|
// @todo What about cowboy_stream_h?
|
|
|
|
Behaviors:
|
|
|
|
* link:man:cowboy_handler(3)[cowboy_handler(3)] - Plain HTTP handlers
|
|
* link:man:cowboy_loop(3)[cowboy_loop(3)] - Loop handlers
|
|
* link:man:cowboy_middleware(3)[cowboy_middleware(3)] - Middlewares
|
|
* link:man:cowboy_rest(3)[cowboy_rest(3)] - REST handlers
|
|
// @todo * link:man:cowboy_stream(3)[cowboy_stream(3)] - Stream handlers
|
|
// @todo * link:man:cowboy_sub_protocol(3)[cowboy_sub_protocol(3)] - Sub protocols
|
|
* link:man:cowboy_websocket(3)[cowboy_websocket(3)] - Websocket handlers
|
|
|
|
Middlewares:
|
|
|
|
* link:man:cowboy_router(3)[cowboy_router(3)] - Router middleware
|
|
* link:man:cowboy_handler(3)[cowboy_handler(3)] - Handler middleware
|
|
|
|
// @todo http_status_codes is not linked to; what to do with it?
|
|
|
|
== Dependencies
|
|
|
|
* link:man:ranch(7)[ranch(7)] - Socket acceptor pool for TCP protocols
|
|
* link:man:cowlib(7)[cowlib(7)] - Support library for manipulating Web protocols
|
|
* ssl - Secure communication over sockets
|
|
* crypto - Crypto functions
|
|
|
|
All these applications must be started before the `cowboy`
|
|
application. To start Cowboy and all dependencies at once:
|
|
|
|
[source,erlang]
|
|
----
|
|
{ok, _} = application:ensure_all_started(cowboy).
|
|
----
|
|
|
|
== Environment
|
|
|
|
The `cowboy` application does not define any application
|
|
environment configuration parameters.
|
|
|
|
== See also
|
|
|
|
link:man:ranch(7)[ranch(7)],
|
|
link:man:cowlib(7)[cowlib(7)]
|