Docs on Nine Nines http://ninenines.eu/docs/ Recent content in Docs on Nine Nines Hugo -- gohugo.io en-us Cowboy Function Reference http://ninenines.eu/docs/en/cowboy/2.0/manual/ Mon, 01 Jan 0001 00:00:00 +0000 http://ninenines.eu/docs/en/cowboy/2.0/manual/ <div class="ulist"><ul> <li> <p> <a href="cowboy_app">cowboy(7)</a> </p> </li> <li> <p> <a href="cowboy">cowboy(3)</a> </p> </li> <li> <p> <a href="cowboy_handler">cowboy_handler(3)</a> </p> </li> <li> <p> <a href="cowboy_loop">cowboy_loop(3)</a> </p> </li> <li> <p> <a href="cowboy_middleware">cowboy_middleware(3)</a> </p> </li> <li> <p> <a href="cowboy_protocol">cowboy_protocol(3)</a> </p> </li> <li> <p> <a href="cowboy_req">cowboy_req(3)</a> </p> </li> <li> <p> <a href="cowboy_rest">cowboy_rest(3)</a> </p> </li> <li> <p> <a href="cowboy_router">cowboy_router(3)</a> </p> </li> <li> <p> <a href="cowboy_static">cowboy_static(3)</a> </p> </li> <li> <p> <a href="cowboy_sub_protocol">cowboy_sub_protocol(3)</a> </p> </li> <li> <p> <a href="cowboy_websocket">cowboy_websocket(3)</a> </p> </li> <li> <p> <a href="http_status_codes">HTTP status codes(7)</a> </p> </li> </ul></div> Cowboy User Guide http://ninenines.eu/docs/en/cowboy/2.0/guide/ Mon, 01 Jan 0001 00:00:00 +0000 http://ninenines.eu/docs/en/cowboy/2.0/guide/ <div class="sect1"> <h2 id="_rationale">Rationale</h2> <div class="sectionbody"> <div class="ulist"><ul> <li> <p> <a href="modern_web/">The modern Web</a> </p> </li> <li> <p> <a href="erlang_web/">Erlang and the Web</a> </p> </li> </ul></div> </div> </div> <div class="sect1"> <h2 id="_introduction">Introduction</h2> <div class="sectionbody"> <div class="ulist"><ul> <li> <p> <a href="introduction/">Introduction</a> </p> </li> <li> <p> <a href="getting_started/">Getting started</a> </p> </li> </ul></div> <div class="ulist"><ul> <li> <p> <a href="flow_diagram/">Flow diagram</a> </p> </li> </ul></div> </div> </div> <div class="sect1"> <h2 id="_configuration">Configuration</h2> <div class="sectionbody"> <div class="ulist"><ul> <li> <p> <a href="listeners/">Listeners</a> </p> </li> <li> <p> <a href="streams/">Streams</a> </p> </li> <li> <p> <a href="routing/">Routing</a> </p> </li> <li> <p> <a href="constraints/">Constraints</a> </p> </li> </ul></div> </div> </div> <div class="sect1"> <h2 id="_handlers">Handlers</h2> <div class="sectionbody"> <div class="ulist"><ul> <li> <p> <a href="handlers/">Handlers</a> </p> </li> <li> <p> <a href="loop_handlers/">Loop handlers</a> </p> </li> <li> <p> <a href="static_files/">Static files</a> </p> </li> </ul></div> </div> </div> <div class="sect1"> <h2 id="_request_and_response">Request and response</h2> <div class="sectionbody"> <div class="ulist"><ul> <li> <p> <a href="req/">Request details</a> </p> </li> <li> <p> <a href="req_body/">Reading the request body</a> </p> </li> <li> <p> <a href="resp/">Sending a response</a> </p> </li> <li> <p> <a href="cookies/">Using cookies</a> </p> </li> <li> <p> <a href="multipart/">Multipart</a> </p> </li> </ul></div> </div> </div> <div class="sect1"> <h2 id="_rest">REST</h2> <div class="sectionbody"> <div class="ulist"><ul> <li> <p> <a href="rest_principles/">REST principles</a> </p> </li> <li> <p> <a href="rest_handlers/">Handling REST requests</a> </p> </li> <li> <p> <a href="rest_flowcharts/">REST flowcharts</a> </p> </li> <li> <p> <a href="resource_design/">Designing a resource handler</a> </p> </li> </ul></div> </div> </div> <div class="sect1"> <h2 id="_websocket">Websocket</h2> <div class="sectionbody"> <div class="ulist"><ul> <li> <p> <a href="ws_protocol/">The Websocket protocol</a> </p> </li> <li> <p> <a href="ws_handlers/">Handling Websocket connections</a> </p> </li> </ul></div> </div> </div> <div class="sect1"> <h2 id="_internals">Internals</h2> <div class="sectionbody"> <div class="ulist"><ul> <li> <p> <a href="architecture/">Architecture</a> </p> </li> </ul></div> <div class="ulist"><ul> <li> <p> <a href="broken_clients/">Dealing with broken clients</a> </p> </li> <li> <p> <a href="middlewares/">Middlewares</a> </p> </li> <li> <p> <a href="sub_protocols/">Sub protocols</a> </p> </li> </ul></div> <div class="ulist"><ul> <li> <p> <a href="hooks/">Hooks</a> </p> </li> </ul></div> </div> </div> Erlang.mk User Guide http://ninenines.eu/docs/en/erlang.mk/1/guide/ Mon, 01 Jan 0001 00:00:00 +0000 http://ninenines.eu/docs/en/erlang.mk/1/guide/ <div class="ulist"><ul> <li> <p> <a href="installation/">Installation</a> </p> </li> <li> <p> <a href="getting_started/">Getting started</a> </p> </li> <li> <p> <a href="overview/">Overview</a> </p> </li> <li> <p> <a href="updating/">Updating Erlang.mk</a> </p> </li> <li> <p> <a href="limitations/">Limitations</a> </p> </li> </ul></div> <div class="sect1"> <h2 id="code">Code</h2> <div class="sectionbody"> <div class="ulist"><ul> <li> <p> <a href="app/">Building</a> </p> </li> <li> <p> <a href="deps/">Packages and dependencies</a> </p> </li> <li> <p> <a href="ports/">NIFs and port drivers</a> </p> </li> <li> <p> <a href="releases/">Releases</a> </p> </li> <li> <p> <a href="escripts/">Escripts</a> </p> </li> <li> <p> <a href="compat/">Compatibility with other build tools</a> </p> </li> </ul></div> </div> </div> <div class="sect1"> <h2 id="docs">Documentation</h2> <div class="sectionbody"> <div class="ulist"><ul> <li> <p> <a href="asciidoc/">Asciidoc documentation</a> </p> </li> <li> <p> <a href="edoc/">EDoc comments</a> </p> </li> </ul></div> </div> </div> <div class="sect1"> <h2 id="tests">Tests</h2> <div class="sectionbody"> <div class="ulist"><ul> <li> <p> <a href="shell/">Erlang shell</a> </p> </li> <li> <p> <a href="eunit/">EUnit</a> </p> </li> <li> <p> <a href="common_test/">Common Test</a> </p> </li> <li> <p> <a href="coverage/">Code coverage</a> </p> </li> <li> <p> <a href="ci/">Continuous integration</a> </p> </li> <li> <p> <a href="dialyzer/">Dialyzer</a> </p> </li> <li> <p> <a href="xref/">Xref</a> </p> </li> </ul></div> </div> </div> <div class="sect1"> <h2 id="plugins">Third-party plugins</h2> <div class="sectionbody"> <div class="ulist"><ul> <li> <p> <a href="external_plugins/">External plugins</a> </p> </li> <li> <p> <a href="external_plugins_list/">List of plugins</a> </p> </li> </ul></div> </div> </div> <div class="sect1"> <h2 id="about">About Erlang.mk</h2> <div class="sectionbody"> <div class="ulist"><ul> <li> <p> <a href="why/">Why erlang.mk?</a> </p> </li> <li> <p> <a href="history/">Short history</a> </p> </li> <li> <p> <a href="contributing/">Contributing</a> </p> </li> </ul></div> </div> </div> Gun Function Reference http://ninenines.eu/docs/en/gun/1.0/manual/ Mon, 01 Jan 0001 00:00:00 +0000 http://ninenines.eu/docs/en/gun/1.0/manual/ <div class="ulist"><ul> <li> <p> <a href="gun_app">gun(7)</a> </p> </li> <li> <p> <a href="gun">gun(3)</a> </p> </li> </ul></div> Gun User Guide http://ninenines.eu/docs/en/gun/1.0/guide/ Mon, 01 Jan 0001 00:00:00 +0000 http://ninenines.eu/docs/en/gun/1.0/guide/ <div class="ulist"><ul> <li> <p> <a href="introduction/">Introduction</a> </p> </li> <li> <p> <a href="start/">Starting and stopping</a> </p> </li> <li> <p> <a href="protocols/">Supported protocols</a> </p> </li> <li> <p> <a href="connect/">Connection</a> </p> </li> <li> <p> <a href="http/">Using HTTP</a> </p> </li> <li> <p> <a href="websocket/">Using Websocket</a> </p> </li> </ul></div> HTTP status codes(7) http://ninenines.eu/docs/en/cowboy/2.0/manual/http_status_codes/ Mon, 01 Jan 0001 00:00:00 +0000 http://ninenines.eu/docs/en/cowboy/2.0/manual/http_status_codes/ <div class="sect1"> <h2 id="_name">Name</h2> <div class="sectionbody"> <div class="paragraph"><p>HTTP status codes - status codes used by Cowboy</p></div> </div> </div> <div class="sect1"> <h2 id="_description">Description</h2> <div class="sectionbody"> <div class="paragraph"><p>This chapter aims to list all HTTP status codes that Cowboy may return, with details on the reasons why. The list given here only includes the replies that Cowboy sends, not user replies.</p></div> </div> </div> <div class="sect1"> <h2 id="_100_continue">100 Continue</h2> <div class="sectionbody"> <div class="paragraph"><p>When the client sends an <code>expect: 100-continue</code> header, Cowboy automatically sends a this status code before trying to read the request body. This behavior can be disabled using the appropriate body option.</p></div> </div> </div> <div class="sect1"> <h2 id="_101_switching_protocols">101 Switching Protocols</h2> <div class="sectionbody"> <div class="paragraph"><p>This is the status code sent when switching to the Websocket protocol.</p></div> </div> </div> <div class="sect1"> <h2 id="_200_ok">200 OK</h2> <div class="sectionbody"> <div class="paragraph"><p>This status code is sent by <code>cowboy_rest</code>.</p></div> </div> </div> <div class="sect1"> <h2 id="_201_created">201 Created</h2> <div class="sectionbody"> <div class="paragraph"><p>This status code is sent by <code>cowboy_rest</code>.</p></div> </div> </div> <div class="sect1"> <h2 id="_202_accepted">202 Accepted</h2> <div class="sectionbody"> <div class="paragraph"><p>This status code is sent by <code>cowboy_rest</code>.</p></div> </div> </div> <div class="sect1"> <h2 id="_204_no_content">204 No Content</h2> <div class="sectionbody"> <div class="paragraph"><p>This status code is sent when the processing of a request ends without any reply having been sent. It may also be sent by <code>cowboy_rest</code> under normal conditions.</p></div> </div> </div> <div class="sect1"> <h2 id="_300_multiple_choices">300 Multiple Choices</h2> <div class="sectionbody"> <div class="paragraph"><p>This status code is sent by <code>cowboy_rest</code>.</p></div> </div> </div> <div class="sect1"> <h2 id="_301_moved_permanently">301 Moved Permanently</h2> <div class="sectionbody"> <div class="paragraph"><p>This status code is sent by <code>cowboy_rest</code>.</p></div> </div> </div> <div class="sect1"> <h2 id="_303_see_other">303 See Other</h2> <div class="sectionbody"> <div class="paragraph"><p>This status code is sent by <code>cowboy_rest</code>.</p></div> </div> </div> <div class="sect1"> <h2 id="_304_not_modified">304 Not Modified</h2> <div class="sectionbody"> <div class="paragraph"><p>This status code is sent by <code>cowboy_rest</code>.</p></div> </div> </div> <div class="sect1"> <h2 id="_307_temporary_redirect">307 Temporary Redirect</h2> <div class="sectionbody"> <div class="paragraph"><p>This status code is sent by <code>cowboy_rest</code>.</p></div> </div> </div> <div class="sect1"> <h2 id="_400_bad_request">400 Bad Request</h2> <div class="sectionbody"> <div class="paragraph"><p>Cowboy will send this status code for any of the following reasons:</p></div> <div class="ulist"><ul> <li> <p> Too many empty lines were sent before the request. </p> </li> <li> <p> The request-line could not be parsed. </p> </li> <li> <p> Too many headers were sent. </p> </li> <li> <p> A header name was too long. </p> </li> <li> <p> A header value was too long. </p> </li> <li> <p> The host header was missing from an HTTP/1.1 request. </p> </li> <li> <p> The host header could not be parsed. </p> </li> <li> <p> The requested host was not found. </p> </li> <li> <p> The requested path could not be parsed. </p> </li> <li> <p> The accept header could not be parsed when using REST. </p> </li> <li> <p> REST under normal conditions. </p> </li> <li> <p> A Websocket upgrade failed. </p> </li> </ul></div> </div> </div> <div class="sect1"> <h2 id="_401_unauthorized">401 Unauthorized</h2> <div class="sectionbody"> <div class="paragraph"><p>This status code is sent by <code>cowboy_rest</code>.</p></div> </div> </div> <div class="sect1"> <h2 id="_403_forbidden">403 Forbidden</h2> <div class="sectionbody"> <div class="paragraph"><p>This status code is sent by <code>cowboy_rest</code>.</p></div> </div> </div> <div class="sect1"> <h2 id="_404_not_found">404 Not Found</h2> <div class="sectionbody"> <div class="paragraph"><p>This status code is sent when the router successfully resolved the host but didn&#8217;t find a matching path for the request. It may also be sent by <code>cowboy_rest</code> under normal conditions.</p></div> </div> </div> <div class="sect1"> <h2 id="_405_method_not_allowed">405 Method Not Allowed</h2> <div class="sectionbody"> <div class="paragraph"><p>This status code is sent by <code>cowboy_rest</code>.</p></div> </div> </div> <div class="sect1"> <h2 id="_406_not_acceptable">406 Not Acceptable</h2> <div class="sectionbody"> <div class="paragraph"><p>This status code is sent by <code>cowboy_rest</code>.</p></div> </div> </div> <div class="sect1"> <h2 id="_408_request_timeout">408 Request Timeout</h2> <div class="sectionbody"> <div class="paragraph"><p>Cowboy will send this status code to the client if the client started to send a request, indicated by the request-line being received fully, but failed to send all headers in a reasonable time.</p></div> </div> </div> <div class="sect1"> <h2 id="_409_conflict">409 Conflict</h2> <div class="sectionbody"> <div class="paragraph"><p>This status code is sent by <code>cowboy_rest</code>.</p></div> </div> </div> <div class="sect1"> <h2 id="_410_gone">410 Gone</h2> <div class="sectionbody"> <div class="paragraph"><p>This status code is sent by <code>cowboy_rest</code>.</p></div> </div> </div> <div class="sect1"> <h2 id="_412_precondition_failed">412 Precondition Failed</h2> <div class="sectionbody"> <div class="paragraph"><p>This status code is sent by <code>cowboy_rest</code>.</p></div> </div> </div> <div class="sect1"> <h2 id="_413_request_entity_too_large">413 Request Entity Too Large</h2> <div class="sectionbody"> <div class="paragraph"><p>This status code is sent by <code>cowboy_rest</code>.</p></div> </div> </div> <div class="sect1"> <h2 id="_414_request_uri_too_long">414 Request-URI Too Long</h2> <div class="sectionbody"> <div class="paragraph"><p>Cowboy will send this status code to the client if the request-line is too long. It may also be sent by <code>cowboy_rest</code> under normal conditions.</p></div> </div> </div> <div class="sect1"> <h2 id="_415_unsupported_media_type">415 Unsupported Media Type</h2> <div class="sectionbody"> <div class="paragraph"><p>This status code is sent by <code>cowboy_rest</code>.</p></div> </div> </div> <div class="sect1"> <h2 id="_500_internal_server_error">500 Internal Server Error</h2> <div class="sectionbody"> <div class="paragraph"><p>This status code is sent when a crash occurs in HTTP, loop or REST handlers, or when an invalid return value is returned. It may also be sent by <code>cowboy_rest</code> under normal conditions.</p></div> </div> </div> <div class="sect1"> <h2 id="_501_not_implemented">501 Not Implemented</h2> <div class="sectionbody"> <div class="paragraph"><p>This status code is sent by <code>cowboy_rest</code>.</p></div> </div> </div> <div class="sect1"> <h2 id="_503_service_unavailable">503 Service Unavailable</h2> <div class="sectionbody"> <div class="paragraph"><p>This status code is sent by <code>cowboy_rest</code>.</p></div> </div> </div> <div class="sect1"> <h2 id="_505_http_version_not_supported">505 HTTP Version Not Supported</h2> <div class="sectionbody"> <div class="paragraph"><p>Cowboy only supports the versions 1.0 and 1.1 of HTTP. In all other cases this status code is sent back to the client and the connection is closed.</p></div> </div> </div> Ranch Function Reference http://ninenines.eu/docs/en/ranch/1.2/manual/ Mon, 01 Jan 0001 00:00:00 +0000 http://ninenines.eu/docs/en/ranch/1.2/manual/ <div class="ulist"><ul> <li> <p> <a href="ranch_app">ranch(7)</a> </p> </li> <li> <p> <a href="ranch">ranch(3)</a> </p> </li> <li> <p> <a href="ranch_protocol">ranch_protocol(3)</a> </p> </li> <li> <p> <a href="ranch_ssl">ranch_ssl(3)</a> </p> </li> <li> <p> <a href="ranch_tcp">ranch_tcp(3)</a> </p> </li> <li> <p> <a href="ranch_transport">ranch_transport(3)</a> </p> </li> </ul></div> Ranch User Guide http://ninenines.eu/docs/en/ranch/1.2/guide/ Mon, 01 Jan 0001 00:00:00 +0000 http://ninenines.eu/docs/en/ranch/1.2/guide/ <div class="ulist"><ul> <li> <p> <a href="introduction/">Introduction</a> </p> </li> <li> <p> <a href="listeners/">Listeners</a> </p> </li> <li> <p> <a href="transports/">Transports</a> </p> </li> <li> <p> <a href="protocols/">Protocols</a> </p> </li> <li> <p> <a href="embedded/">Embedded mode</a> </p> </li> <li> <p> <a href="parsers/">Writing parsers</a> </p> </li> <li> <p> <a href="ssl_auth/">SSL client authentication</a> </p> </li> <li> <p> <a href="internals/">Internals</a> </p> </li> </ul></div> Request overview http://ninenines.eu/docs/en/cowboy/2.0/guide/overview/ Mon, 01 Jan 0001 00:00:00 +0000 http://ninenines.eu/docs/en/cowboy/2.0/guide/overview/ <div class="paragraph"><p>This chapter explains the different steps a request goes through until a response is sent, along with details of the Cowboy implementation.</p></div> <div class="sect1"> <h2 id="_request_response">Request/response</h2> <div class="sectionbody"> <div class="paragraph"><p>As you already know, HTTP clients connect to the server and send a request for a resource; the server then sends a response containing the resource if it could obtain it.</p></div> <div class="paragraph"><p>Before the server can send the resource, however, it needs to perform many different operations to read the request, find the resource, prepare the response being sent and often other related operations the user can add like writing logs.</p></div> <div class="paragraph"><p>Requests take the following route in Cowboy:</p></div> <div class="imageblock"> <div class="content"> <img src="../http_req_resp.png" alt="HTTP request/response flowchart" /> </div> </div> <div class="paragraph"><p>This shows the default middlewares, but they may be configured differently in your setup. The dark green indicates the points where you can hook your own code, the light green is the Cowboy code that you can of course configure as needed.</p></div> <div class="paragraph"><p>The <code>acceptor</code> is the part of the server that accepts the connection and create an Erlang process to handle it. The <code>parser</code> then starts reading from the socket and handling requests as they come until the socket is closed.</p></div> <div class="paragraph"><p>A response may be sent at many different points in the life of the request. If Cowboy can&#8217;t parse the request, it gives up with an error response. If the router can&#8217;t find the resource, it sends a not found error. Your own code can of course send a response at any time.</p></div> <div class="paragraph"><p>When a response is sent, you can optionally modify it or act upon it by enabling the <code>onresponse</code> hook. By default the response is sent directly to the client.</p></div> </div> </div> <div class="sect1"> <h2 id="_and_then">And then?</h2> <div class="sectionbody"> <div class="paragraph"><p>Behavior depends on what protocol is in use.</p></div> <div class="paragraph"><p>HTTP/1.0 can only process one request per connection, so Cowboy will close the connection immediately after it sends the response.</p></div> <div class="paragraph"><p>HTTP/1.1 allows the client to request that the server keeps the connection alive. This mechanism is described in the next section.</p></div> <div class="paragraph"><p>HTTP/2 is designed to allow sending multiple requests asynchronously on the same connection. Details on what this means for your application is described in this chapter.</p></div> </div> </div> <div class="sect1"> <h2 id="_keep_alive_http_1_1">Keep-alive (HTTP/1.1)</h2> <div class="sectionbody"> <div class="paragraph"><p>With HTTP/1.1, the connection may be left open for subsequent requests to come. This mechanism is called <code>keep-alive</code>.</p></div> <div class="paragraph"><p>When the client sends a request to the server, it includes a header indicating whether it would like to leave the socket open. The server may or may not accept, indicating its choice by sending the same header in the response.</p></div> <div class="paragraph"><p>Cowboy will include this header automatically in all responses to HTTP/1.1 requests. You can however force the closing of the socket if you want. When Cowboy sees you want to send a <code>connection: close</code> header, it will not override it and will close the connection as soon as the reply is sent.</p></div> <div class="paragraph"><p>This snippet will force Cowboy to close the connection.</p></div> <div class="listingblock"> <div class="content"><!-- Generator: GNU source-highlight 3.1.8 by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite --> <pre><tt><span style="color: #009900">Req2</span> <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">cowboy_req:reply</span></span>(<span style="color: #993399">200</span>, [ {<span style="color: #990000">&lt;&lt;</span><span style="color: #FF0000">"connection"</span><span style="color: #990000">&gt;&gt;</span>, <span style="color: #990000">&lt;&lt;</span><span style="color: #FF0000">"close"</span><span style="color: #990000">&gt;&gt;</span>}, ], <span style="color: #990000">&lt;&lt;</span><span style="color: #FF0000">"Closing the socket in 3.. 2.. 1.."</span><span style="color: #990000">&gt;&gt;</span>, <span style="color: #009900">Req</span>)<span style="color: #990000">.</span></tt></pre></div></div> <div class="paragraph"><p>Cowboy will only accept a certain number of new requests on the same connection. By default it will run up to 100 requests. This number can be changed by setting the <code>max_keepalive</code> configuration value when starting an HTTP listener.</p></div> <div class="listingblock"> <div class="content"><!-- Generator: GNU source-highlight 3.1.8 by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite --> <pre><tt><span style="font-weight: bold"><span style="color: #000000">cowboy:start_http</span></span>(<span style="color: #FF6600">my_http_listener</span>, <span style="color: #993399">100</span>, [{<span style="color: #FF6600">port</span>, <span style="color: #993399">8080</span>}], [ {<span style="color: #FF6600">env</span>, [{<span style="color: #FF6600">dispatch</span>, <span style="color: #009900">Dispatch</span>}]}, {<span style="color: #FF6600">max_keepalive</span>, <span style="color: #993399">5</span>} ])<span style="color: #990000">.</span></tt></pre></div></div> <div class="paragraph"><p>Cowboy implements the keep-alive mechanism by reusing the same process for all requests. This allows Cowboy to save memory. This works well because most code will not have any side effect impacting subsequent requests. But it also means you need to clean up if you do have code with side effects. The <code>terminate/3</code> function can be used for this purpose.</p></div> </div> </div> <div class="sect1"> <h2 id="_pipelining_http_1_1">Pipelining (HTTP/1.1)</h2> <div class="sectionbody"> <div class="paragraph"><p>While HTTP is designed as a sequential protocol, with the client sending a request and then waiting for the response from the server, nothing prevents the client from sending more requests to the server without waiting for the response, due to how sockets work. The server still handles the requests sequentially and sends the responses in the same order.</p></div> <div class="paragraph"><p>This mechanism is called pipelining. It allows reducing latency when a client needs to request many resources at the same time. This is used by browsers when requesting static files for example.</p></div> <div class="paragraph"><p>This is handled automatically by the server.</p></div> </div> </div> <div class="sect1"> <h2 id="_asynchronous_requests_http_2">Asynchronous requests (HTTP/2)</h2> <div class="sectionbody"> <div class="paragraph"><p>In HTTP/2, the client can send a request at any time. And the server can send a response at any time too.</p></div> <div class="paragraph"><p>This means for example that the client does not need to wait for a request to be fully sent to send another, it is possible to interleave a request with the request body of another request. The same is true with responses. Responses may also be sent in a different order.</p></div> <div class="paragraph"><p>Because requests and responses are fully asynchronous, Cowboy creates a new process for each request, and these processes are managed by another process that handles the connection itself.</p></div> <div class="paragraph"><p>HTTP/2 servers may also decide to send resources to the client before the client requests them. This is especially useful for sending static files associated with the HTML page requested, as this reduces the latency of the overall response. Cowboy does not support this particular mechanism at this point, however.</p></div> </div> </div> cowboy(3) http://ninenines.eu/docs/en/cowboy/2.0/manual/cowboy/ Mon, 01 Jan 0001 00:00:00 +0000 http://ninenines.eu/docs/en/cowboy/2.0/manual/cowboy/ <div class="sect1"> <h2 id="_name">Name</h2> <div class="sectionbody"> <div class="paragraph"><p>cowboy - HTTP server</p></div> </div> </div> <div class="sect1"> <h2 id="_description">Description</h2> <div class="sectionbody"> <div class="paragraph"><p>The <code>cowboy</code> module provides convenience functions for manipulating Ranch listeners.</p></div> </div> </div> <div class="sect1"> <h2 id="_types">Types</h2> <div class="sectionbody"> <div class="sect2"> <h3 id="_fields_field">fields() = [Field]</h3> <div class="listingblock"> <div class="content"><!-- Generator: GNU source-highlight 3.1.8 by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite --> <pre><tt><span style="color: #009900">Field</span> <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000080">atom</span></span>() | {<span style="font-weight: bold"><span style="color: #000080">atom</span></span>(), <span style="font-weight: bold"><span style="color: #000000">cowboy_constraints:constraint</span></span>() | [<span style="font-weight: bold"><span style="color: #000000">cowboy_constraints:constraint</span></span>()]} | {<span style="font-weight: bold"><span style="color: #000080">atom</span></span>(), <span style="font-weight: bold"><span style="color: #000000">cowboy_constraints:constraint</span></span>() | [<span style="font-weight: bold"><span style="color: #000000">cowboy_constraints:constraint</span></span>()], <span style="font-weight: bold"><span style="color: #000000">any</span></span>()}]</tt></pre></div></div> <div class="paragraph"><p>Fields for match operations. Constraint(s) and default value are optional.</p></div> </div> <div class="sect2"> <h3 id="_http_headers_binary_iodata">http_headers() = [{binary(), iodata()}]</h3> <div class="paragraph"><p>HTTP headers as a list of key/values.</p></div> </div> <div class="sect2"> <h3 id="_http_status_non_neg_integer_binary">http_status() = non_neg_integer() | binary()</h3> <div class="paragraph"><p>HTTP status.</p></div> <div class="paragraph"><p>A binary status can be used to set a custom message.</p></div> </div> <div class="sect2"> <h3 id="_http_version_http_1_1_http_1_0">http_version() = 'HTTP/1.1' | 'HTTP/1.0'</h3> <div class="paragraph"><p>HTTP version.</p></div> </div> <div class="sect2"> <h3 id="_code_onresponse_fun_fun_http_status_http_headers_iodata_cowboy_req_req_gt_cowboy_req_req_code"><code>onresponse_fun() = fun((http_status(), http_headers(), iodata(), cowboy_req:req()) -&gt; cowboy_req:req())</code></h3> <div class="paragraph"><p>Fun called immediately before sending the response.</p></div> <div class="paragraph"><p>It can perform any operation on the Req object, including reading the request body or replying. If a reply is sent, it overrides the reply initially sent. The callback will not be called again for the new reply.</p></div> </div> </div> </div> <div class="sect1"> <h2 id="_exports">Exports</h2> <div class="sectionbody"> <div class="sect2"> <h3 id="_start_http_ref_nbacceptors_transopts_protoopts_8594_ok_pid">start_http(Ref, NbAcceptors, TransOpts, ProtoOpts) &#8594; {ok, pid()}</h3> <div class="dlist"><dl> <dt class="hdlist1"> Ref = ranch:ref() </dt> <dd> <p> Listener name. </p> </dd> <dt class="hdlist1"> NbAcceptors = non_neg_integer() </dt> <dd> <p> Number of acceptor processes. </p> </dd> <dt class="hdlist1"> TransOpts = ranch_tcp:opts() </dt> <dd> <p> TCP transport options. </p> </dd> <dt class="hdlist1"> ProtoOpts = cowboy_protocol:opts() </dt> <dd> <p> HTTP protocol options. </p> </dd> </dl></div> <div class="paragraph"><p>Start listening for HTTP connections. Returns the pid for this listener&#8217;s supervisor.</p></div> </div> <div class="sect2"> <h3 id="_start_https_ref_nbacceptors_transopts_protoopts_8594_ok_pid">start_https(Ref, NbAcceptors, TransOpts, ProtoOpts) &#8594; {ok, pid()}</h3> <div class="dlist"><dl> <dt class="hdlist1"> Ref = ranch:ref() </dt> <dd> <p> Listener name. </p> </dd> <dt class="hdlist1"> NbAcceptors = non_neg_integer() </dt> <dd> <p> Number of acceptor processes. </p> </dd> <dt class="hdlist1"> TransOpts = ranch_ssl:opts() </dt> <dd> <p> SSL transport options. </p> </dd> <dt class="hdlist1"> ProtoOpts = cowboy_protocol:opts() </dt> <dd> <p> HTTP protocol options. </p> </dd> </dl></div> <div class="paragraph"><p>Start listening for HTTPS connections. Returns the pid for this listener&#8217;s supervisor.</p></div> </div> <div class="sect2"> <h3 id="_stop_listener_ref_8594_ok_error_not_found">stop_listener(Ref) &#8594; ok | {error, not_found}</h3> <div class="dlist"><dl> <dt class="hdlist1"> Ref = ranch:ref() </dt> <dd> <p> Listener name. </p> </dd> </dl></div> <div class="paragraph"><p>Stop a previously started listener.</p></div> </div> <div class="sect2"> <h3 id="_set_env_ref_name_value_8594_ok">set_env(Ref, Name, Value) &#8594; ok</h3> <div class="dlist"><dl> <dt class="hdlist1"> Ref = ranch:ref() </dt> <dd> <p> Listener name. </p> </dd> <dt class="hdlist1"> Name = atom() </dt> <dd> <p> Name of environment value. </p> </dd> <dt class="hdlist1"> Value = any() </dt> <dd> <p> Environment value. </p> </dd> </dl></div> <div class="paragraph"><p>Set or update an environment value for an already running listener. This will take effect on all subsequent connections.</p></div> </div> </div> </div> <div class="sect1"> <h2 id="_see_also">See also</h2> <div class="sectionbody"> <div class="paragraph"><p>The <a href="http://ninenines.eu/docs/en/ranch/HEAD/guide">Ranch guide</a> provides detailed information about how listeners work.</p></div> </div> </div> cowboy(7) http://ninenines.eu/docs/en/cowboy/2.0/manual/cowboy_app/ Mon, 01 Jan 0001 00:00:00 +0000 http://ninenines.eu/docs/en/cowboy/2.0/manual/cowboy_app/ <div class="sect1"> <h2 id="_name">Name</h2> <div class="sectionbody"> <div class="paragraph"><p>cowboy - Small, fast, modular HTTP server.</p></div> </div> </div> <div class="sect1"> <h2 id="_dependencies">Dependencies</h2> <div class="sectionbody"> <div class="paragraph"><p>The <code>cowboy</code> application uses the Erlang applications <code>ranch</code> for listening and accepting TCP connections, <code>crypto</code> for establishing Websocket connections, and <code>cowlib</code> for parsing and building messages for Web protocols. These dependencies must be loaded for the <code>cowboy</code> application to work. In an embedded environment this means that they need to be started with the <code>application:start/{1,2}</code> function before the <code>cowboy</code> application is started.</p></div> <div class="paragraph"><p>The <code>cowboy</code> application also uses the Erlang applications <code>asn1</code>, <code>public_key</code> and <code>ssl</code> when listening for HTTPS connections. These are started automatically if they weren&#8217;t before.</p></div> </div> </div> <div class="sect1"> <h2 id="_environment">Environment</h2> <div class="sectionbody"> <div class="paragraph"><p>The <code>cowboy</code> application does not define any application environment configuration parameters.</p></div> </div> </div> cowboy_handler(3) http://ninenines.eu/docs/en/cowboy/2.0/manual/cowboy_handler/ Mon, 01 Jan 0001 00:00:00 +0000 http://ninenines.eu/docs/en/cowboy/2.0/manual/cowboy_handler/ <div class="sect1"> <h2 id="_name">Name</h2> <div class="sectionbody"> <div class="paragraph"><p>cowboy_handler - handler middleware and behaviour</p></div> </div> </div> <div class="sect1"> <h2 id="_description">Description</h2> <div class="sectionbody"> <div class="paragraph"><p>The <code>cowboy_handler</code> middleware executes the handler passed through the environment values <code>handler</code> and <code>handler_opts</code>, and adds the result of this execution to the environment as the value <code>result</code>, indicating that the request has been handled and received a response.</p></div> <div class="paragraph"><p>Environment input:</p></div> <div class="dlist"><dl> <dt class="hdlist1"> handler = module() </dt> <dd> <p> Handler to be executed. </p> </dd> <dt class="hdlist1"> handler_opts = any() </dt> <dd> <p> Options to be passed to the handler. </p> </dd> </dl></div> <div class="paragraph"><p>Environment output:</p></div> <div class="dlist"><dl> <dt class="hdlist1"> result = ok </dt> <dd> <p> Result of the request. </p> </dd> </dl></div> <div class="paragraph"><p>This module also defines the <code>cowboy_handler</code> behaviour that defines the basic interface for handlers. All Cowboy handlers implement at least the <code>init/2</code> callback, and may implement the <code>terminate/3</code> callback optionally.</p></div> </div> </div> <div class="sect1"> <h2 id="_terminate_reasons">Terminate reasons</h2> <div class="sectionbody"> <div class="paragraph"><p>The following values may be received as the terminate reason in the optional <code>terminate/3</code> callback. Different handler types may define additional terminate reasons.</p></div> <div class="dlist"><dl> <dt class="hdlist1"> normal </dt> <dd> <p> The connection was closed normally. </p> </dd> <dt class="hdlist1"> {crash, Class, Reason} </dt> <dd> <p> A crash occurred in the handler. <code>Class</code> and <code>Reason</code> can be used to obtain more information about the crash. The function <code>erlang:get_stacktrace/0</code> can also be called to obtain the stacktrace of the process when the crash occurred. </p> </dd> </dl></div> </div> </div> <div class="sect1"> <h2 id="_callbacks">Callbacks</h2> <div class="sectionbody"> <div class="sect2"> <h3 id="_init_req_opts_8594_ok_req_state_module_req_state_module_req_state_hibernate_timeout_module_req_state_timeout_hibernate">init(Req, Opts) &#8594; {ok, Req, State} | {Module, Req, State} | {Module, Req, State, hibernate | Timeout} | {Module, Req, State, Timeout, hibernate}</h3> <div class="dlist"><dl> <dt class="hdlist1"> Req = cowboy_req:req() </dt> <dd> <p> The Req object. </p> </dd> <dt class="hdlist1"> Opts = any() </dt> <dd> <p> Handler options. </p> </dd> <dt class="hdlist1"> State = any() </dt> <dd> <p> Handler state. </p> </dd> <dt class="hdlist1"> Module = module() </dt> <dd> <p> Module of the sub-protocol to use. </p> </dd> <dt class="hdlist1"> Timeout = timeout() </dt> <dd> <p> Timeout passed to the sub-protocol, when applicable. </p> </dd> </dl></div> <div class="paragraph"><p>Process the request.</p></div> <div class="paragraph"><p>This function can be used to switch to an alternate handler type by returning the name of the module to be used, along with a few options.</p></div> <div class="paragraph"><p>For basic handlers this is the function where the response should be sent. If no response is sent, Cowboy will ensure that a <code>204 No Content</code> response is sent.</p></div> <div class="paragraph"><p>A crash in this callback will result in <code>terminate/3</code> being called if it is defined, with the <code>State</code> argument set to the value of <code>Opts</code> originally given to the <code>init/2</code> callback.</p></div> </div> <div class="sect2"> <h3 id="_terminate_reason_req_state_8594_ok">terminate(Reason, Req, State) &#8594; ok</h3> <div class="dlist"><dl> <dt class="hdlist1"> Reason = any() </dt> <dd> <p> Reason for termination. </p> </dd> <dt class="hdlist1"> Req = cowboy_req:req() </dt> <dd> <p> The Req object. </p> </dd> <dt class="hdlist1"> State = any() </dt> <dd> <p> Handler state. </p> </dd> </dl></div> <div class="paragraph"><p>Perform any necessary cleanup of the state.</p></div> <div class="paragraph"><p>This callback should release any resource currently in use, clear any active timer and reset the process to its original state, as it might be reused for future requests sent on the same connection. Typical plain HTTP handlers rarely need to use it.</p></div> <div class="paragraph"><p>A crash in this callback or an invalid return value will result in the closing of the connection and the termination of the process.</p></div> </div> </div> </div> <div class="sect1"> <h2 id="_exports">Exports</h2> <div class="sectionbody"> <div class="sect2"> <h3 id="_terminate_reason_req_state_handler_8594_ok">terminate(Reason, Req, State, Handler) &#8594; ok</h3> <div class="dlist"><dl> <dt class="hdlist1"> Reason = any() </dt> <dd> <p> Reason for termination. </p> </dd> <dt class="hdlist1"> Req = cowboy_req:req() </dt> <dd> <p> The Req object. </p> </dd> <dt class="hdlist1"> State = any() </dt> <dd> <p> Handler state. </p> </dd> <dt class="hdlist1"> Handler = module() </dt> <dd> <p> Handler module. </p> </dd> </dl></div> <div class="paragraph"><p>Call the optional <code>terminate/3</code> callback if it exists.</p></div> <div class="paragraph"><p>This function should always be called at the end of the execution of a handler, to give it a chance to clean up or perform miscellaneous operations.</p></div> </div> </div> </div> cowboy_loop(3) http://ninenines.eu/docs/en/cowboy/2.0/manual/cowboy_loop/ Mon, 01 Jan 0001 00:00:00 +0000 http://ninenines.eu/docs/en/cowboy/2.0/manual/cowboy_loop/ <div class="sect1"> <h2 id="_name">Name</h2> <div class="sectionbody"> <div class="paragraph"><p>cowboy_loop - loop handlers</p></div> </div> </div> <div class="sect1"> <h2 id="_description">Description</h2> <div class="sectionbody"> <div class="paragraph"><p>The <code>cowboy_loop</code> module implements a handler interface for long running HTTP connections. It is the recommended interface for long polling and server-sent events, amongst others.</p></div> <div class="paragraph"><p>This module is a sub protocol that defines three callbacks to be implemented by handlers. The <code>init/2</code> and <code>terminate/3</code> callbacks are common to all handler types and are documented in the manual for the <a href="cowboy_handler.asciidoc">cowboy_handler</a> module.</p></div> <div class="paragraph"><p>The <code>info/3</code> callback is specific to loop handlers and will be called as many times as necessary until a reply is sent.</p></div> <div class="paragraph"><p>It is highly recommended to return a timeout value from the <code>init/2</code> callback to ensure that the process is terminated when no data has been received during that timespan. The default timeout is <code>infinity</code>, which should only be used if you have alternate means of ending inactive connections.</p></div> </div> </div> <div class="sect1"> <h2 id="_terminate_reasons">Terminate reasons</h2> <div class="sectionbody"> <div class="paragraph"><p>The following values may be received as the terminate reason in the optional <code>terminate/3</code> callback.</p></div> <div class="dlist"><dl> <dt class="hdlist1"> normal </dt> <dd> <p> The connection was closed normally before switching to the loop sub protocol. This typically happens if an <code>ok</code> tuple is returned from the <code>init/2</code> callback. </p> </dd> <dt class="hdlist1"> stop </dt> <dd> <p> The handler requested to close the connection by returning a <code>stop</code> tuple. </p> </dd> <dt class="hdlist1"> timeout </dt> <dd> <p> The connection has been closed due to inactivity. The timeout value can be configured from <code>init/2</code>. The response sent when this happens is a <code>204 No Content</code>. </p> </dd> <dt class="hdlist1"> {crash, Class, Reason} </dt> <dd> <p> A crash occurred in the handler. <code>Class</code> and <code>Reason</code> can be used to obtain more information about the crash. The function <code>erlang:get_stacktrace/0</code> can also be called to obtain the stacktrace of the process when the crash occurred. </p> </dd> <dt class="hdlist1"> {error, overflow} </dt> <dd> <p> The connection is being closed and the process terminated because the buffer Cowboy uses to keep data sent by the client has reached its maximum. The buffer size can be configured through the environment value <code>loop_max_buffer</code> and defaults to 5000 bytes. <br /> If the long running request comes with a body it is recommended to process this body before switching to the loop sub protocol. </p> </dd> <dt class="hdlist1"> {error, closed} </dt> <dd> <p> The socket has been closed brutally without a close frame being received first. </p> </dd> <dt class="hdlist1"> {error, Reason} </dt> <dd> <p> A socket error ocurred. </p> </dd> </dl></div> </div> </div> <div class="sect1"> <h2 id="_callbacks">Callbacks</h2> <div class="sectionbody"> <div class="sect2"> <h3 id="_info_info_req_state_8594_ok_req_state_ok_req_state_hibernate_stop_req_state">info(Info, Req, State) &#8594; {ok, Req, State} | {ok, Req, State, hibernate} | {stop, Req, State}</h3> <div class="dlist"><dl> <dt class="hdlist1"> Info = any() </dt> <dd> <p> Message received by the process. </p> </dd> <dt class="hdlist1"> Req = cowboy_req:req() </dt> <dd> <p> The Req object. </p> </dd> <dt class="hdlist1"> State = any() </dt> <dd> <p> Handler state. </p> </dd> </dl></div> <div class="paragraph"><p>Handle the Erlang message received.</p></div> <div class="paragraph"><p>This function will be called every time an Erlang message has been received. The message can be any Erlang term.</p></div> <div class="paragraph"><p>The <code>stop</code> return value can be used to stop the receive loop, typically because a response has been sent.</p></div> <div class="paragraph"><p>The <code>hibernate</code> option will hibernate the process until it receives another message.</p></div> </div> </div> </div> cowboy_middleware(3) http://ninenines.eu/docs/en/cowboy/2.0/manual/cowboy_middleware/ Mon, 01 Jan 0001 00:00:00 +0000 http://ninenines.eu/docs/en/cowboy/2.0/manual/cowboy_middleware/ <div class="sect1"> <h2 id="_name">Name</h2> <div class="sectionbody"> <div class="paragraph"><p>cowboy_middleware - behaviour for middlewares</p></div> </div> </div> <div class="sect1"> <h2 id="_description">Description</h2> <div class="sectionbody"> <div class="paragraph"><p>The <code>cowboy_middleware</code> behaviour defines the interface used by Cowboy middleware modules.</p></div> <div class="paragraph"><p>Middlewares process the request sequentially in the order they are configured.</p></div> </div> </div> <div class="sect1"> <h2 id="_types">Types</h2> <div class="sectionbody"> <div class="sect2"> <h3 id="_env_atom_any">env() = [{atom(), any()}]</h3> <div class="paragraph"><p>The environment variable.</p></div> <div class="paragraph"><p>One is created for every request. It is passed to each middleware module executed and subsequently returned, optionally with its contents modified.</p></div> </div> </div> </div> <div class="sect1"> <h2 id="_callbacks">Callbacks</h2> <div class="sectionbody"> <div class="sect2"> <h3 id="_execute_req_env_8594_ok_req_env_suspend_module_function_args_stop_req">execute(Req, Env) &#8594; {ok, Req, Env} | {suspend, Module, Function, Args} | {stop, Req}</h3> <div class="dlist"><dl> <dt class="hdlist1"> Req = cowboy_req:req() </dt> <dd> <p> The Req object. </p> </dd> <dt class="hdlist1"> Env = env() </dt> <dd> <p> The request environment. </p> </dd> <dt class="hdlist1"> Module = module() </dt> <dd> <p> MFA to call when resuming the process. </p> </dd> <dt class="hdlist1"> Function = atom() </dt> <dd> <p> MFA to call when resuming the process. </p> </dd> <dt class="hdlist1"> Args = [any()] </dt> <dd> <p> MFA to call when resuming the process. </p> </dd> </dl></div> <div class="paragraph"><p>Execute the middleware.</p></div> <div class="paragraph"><p>The <code>ok</code> return value indicates that everything went well and that Cowboy should continue processing the request. A response may or may not have been sent.</p></div> <div class="paragraph"><p>The <code>suspend</code> return value will hibernate the process until an Erlang message is received. Note that when resuming, any previous stacktrace information will be gone.</p></div> <div class="paragraph"><p>The <code>stop</code> return value stops Cowboy from doing any further processing of the request, even if there are middlewares that haven&#8217;t been executed yet. The connection may be left open to receive more requests from the client.</p></div> </div> </div> </div> cowboy_protocol(3) http://ninenines.eu/docs/en/cowboy/2.0/manual/cowboy_protocol/ Mon, 01 Jan 0001 00:00:00 +0000 http://ninenines.eu/docs/en/cowboy/2.0/manual/cowboy_protocol/ <div class="sect1"> <h2 id="_name">Name</h2> <div class="sectionbody"> <div class="paragraph"><p>cowboy_protocol - HTTP protocol</p></div> </div> </div> <div class="sect1"> <h2 id="_description">Description</h2> <div class="sectionbody"> <div class="paragraph"><p>The <code>cowboy_protocol</code> module implements HTTP/1.1 and HTTP/1.0 as a Ranch protocol.</p></div> </div> </div> <div class="sect1"> <h2 id="_types">Types</h2> <div class="sectionbody"> <div class="sect2"> <h3 id="_opts_option">opts() = [Option]</h3> <div class="listingblock"> <div class="content"><!-- Generator: GNU source-highlight 3.1.8 by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite --> <pre><tt><span style="color: #009900">Option</span> <span style="color: #990000">=</span> {<span style="color: #FF6600">compress</span>, <span style="font-weight: bold"><span style="color: #000000">boolean</span></span>()} | {<span style="color: #FF6600">env</span>, <span style="font-weight: bold"><span style="color: #000000">cowboy_middleware:env</span></span>()} | {<span style="color: #FF6600">max_empty_lines</span>, <span style="font-weight: bold"><span style="color: #000000">non_neg_integer</span></span>()} | {<span style="color: #FF6600">max_header_name_length</span>, <span style="font-weight: bold"><span style="color: #000000">non_neg_integer</span></span>()} | {<span style="color: #FF6600">max_header_value_length</span>, <span style="font-weight: bold"><span style="color: #000000">non_neg_integer</span></span>()} | {<span style="color: #FF6600">max_headers</span>, <span style="font-weight: bold"><span style="color: #000000">non_neg_integer</span></span>()} | {<span style="color: #FF6600">max_keepalive</span>, <span style="font-weight: bold"><span style="color: #000000">non_neg_integer</span></span>()} | {<span style="color: #FF6600">max_request_line_length</span>, <span style="font-weight: bold"><span style="color: #000000">non_neg_integer</span></span>()} | {<span style="color: #FF6600">middlewares</span>, [<span style="font-weight: bold"><span style="color: #000000">module</span></span>()]} | {<span style="color: #FF6600">onresponse</span>, <span style="font-weight: bold"><span style="color: #000000">cowboy:onresponse_fun</span></span>()} | {<span style="color: #FF6600">timeout</span>, <span style="font-weight: bold"><span style="color: #000000">timeout</span></span>()}</tt></pre></div></div> <div class="paragraph"><p>Configuration for the HTTP protocol handler.</p></div> <div class="paragraph"><p>This configuration is passed to Cowboy when starting listeners using <code>cowboy:start_http/4</code> or <code>cowboy:start_https/4</code> functions.</p></div> <div class="paragraph"><p>It can be updated without restarting listeners using the Ranch functions <code>ranch:get_protocol_options/1</code> and <code>ranch:set_protocol_options/2</code>.</p></div> </div> <div class="sect2"> <h3 id="_option_descriptions">Option descriptions</h3> <div class="paragraph"><p>The default value is given next to the option name.</p></div> <div class="dlist"><dl> <dt class="hdlist1"> compress (false) </dt> <dd> <p> When enabled, Cowboy will attempt to compress the response body. </p> </dd> <dt class="hdlist1"> env ([{listener, Ref}]) </dt> <dd> <p> Initial middleware environment. </p> </dd> <dt class="hdlist1"> max_empty_lines (5) </dt> <dd> <p> Maximum number of empty lines before a request. </p> </dd> <dt class="hdlist1"> max_header_name_length (64) </dt> <dd> <p> Maximum length of header names. </p> </dd> <dt class="hdlist1"> max_header_value_length (4096) </dt> <dd> <p> Maximum length of header values. </p> </dd> <dt class="hdlist1"> max_headers (100) </dt> <dd> <p> Maximum number of headers allowed per request. </p> </dd> <dt class="hdlist1"> max_keepalive (100) </dt> <dd> <p> Maximum number of requests allowed per connection. </p> </dd> <dt class="hdlist1"> max_request_line_length (4096) </dt> <dd> <p> Maximum length of the request line. </p> </dd> <dt class="hdlist1"> middlewares ([cowboy_router, cowboy_handler]) </dt> <dd> <p> List of middlewares to execute for every requests. </p> </dd> <dt class="hdlist1"> onresponse (undefined) </dt> <dd> <p> Fun called every time a response is sent. </p> </dd> <dt class="hdlist1"> timeout (5000) </dt> <dd> <p> Time in ms with no requests before Cowboy closes the connection. </p> </dd> </dl></div> </div> </div> </div>