diff options
author | Loïc Hoguin <[email protected]> | 2016-10-01 00:08:31 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2016-10-01 00:08:31 +0200 |
commit | 83f1ad46e84c1a9016c9dee2c1ec749880dfd260 (patch) | |
tree | 255dee9f634e4e4395cc48ece6b307f131da30d2 /docs/index.xml | |
parent | 348cfe494318d0c12072fd75ff451c3b40168965 (diff) | |
download | ninenines.eu-83f1ad46e84c1a9016c9dee2c1ec749880dfd260.tar.gz ninenines.eu-83f1ad46e84c1a9016c9dee2c1ec749880dfd260.tar.bz2 ninenines.eu-83f1ad46e84c1a9016c9dee2c1ec749880dfd260.zip |
HTTPS fixes and link:man support in docs + doc update
Diffstat (limited to 'docs/index.xml')
-rw-r--r-- | docs/index.xml | 1264 |
1 files changed, 644 insertions, 620 deletions
diff --git a/docs/index.xml b/docs/index.xml index d301fc08..6ec370a3 100644 --- a/docs/index.xml +++ b/docs/index.xml @@ -2,18 +2,18 @@ <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> <channel> <title>Docs on Nine Nines</title> - <link>http://ninenines.eu/docs/</link> + <link>https://ninenines.eu/docs/</link> <description>Recent content in Docs on Nine Nines</description> <generator>Hugo -- gohugo.io</generator> <language>en-us</language> - <atom:link href="http://ninenines.eu/docs/index.xml" rel="self" type="application/rss+xml" /> + <atom:link href="https://ninenines.eu/docs/index.xml" rel="self" type="application/rss+xml" /> <item> <title>Cowboy Function Reference</title> - <link>http://ninenines.eu/docs/en/cowboy/2.0/manual/</link> + <link>https://ninenines.eu/docs/en/cowboy/2.0/manual/</link> <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> - <guid>http://ninenines.eu/docs/en/cowboy/2.0/manual/</guid> + <guid>https://ninenines.eu/docs/en/cowboy/2.0/manual/</guid> <description><div class="ulist"><ul>
<li>
<p>
@@ -62,11 +62,31 @@ </li>
<li>
<p>
+<a href="cowboy.set_env">cowboy:set_env(3)</a>
+</p>
+</li>
+<li>
+<p>
+<a href="cowboy.start_clear">cowboy:start_clear(3)</a>
+</p>
+</li>
+<li>
+<p>
+<a href="cowboy.start_tls">cowboy:start_tls(3)</a>
+</p>
+</li>
+<li>
+<p>
<a href="cowboy_static">cowboy_static(3)</a>
</p>
</li>
<li>
<p>
+<a href="cowboy.stop_listener">cowboy:stop_listener(3)</a>
+</p>
+</li>
+<li>
+<p>
<a href="cowboy_sub_protocol">cowboy_sub_protocol(3)</a>
</p>
</li>
@@ -86,10 +106,10 @@ <item> <title>Cowboy User Guide</title> - <link>http://ninenines.eu/docs/en/cowboy/2.0/guide/</link> + <link>https://ninenines.eu/docs/en/cowboy/2.0/guide/</link> <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> - <guid>http://ninenines.eu/docs/en/cowboy/2.0/guide/</guid> + <guid>https://ninenines.eu/docs/en/cowboy/2.0/guide/</guid> <description><div class="sect1">
<h2 id="_rationale">Rationale</h2>
<div class="sectionbody">
@@ -297,10 +317,10 @@ <item> <title>Erlang.mk User Guide</title> - <link>http://ninenines.eu/docs/en/erlang.mk/1/guide/</link> + <link>https://ninenines.eu/docs/en/erlang.mk/1/guide/</link> <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> - <guid>http://ninenines.eu/docs/en/erlang.mk/1/guide/</guid> + <guid>https://ninenines.eu/docs/en/erlang.mk/1/guide/</guid> <description><div class="ulist"><ul>
<li>
<p>
@@ -468,10 +488,10 @@ <item> <title>Gun Function Reference</title> - <link>http://ninenines.eu/docs/en/gun/1.0/manual/</link> + <link>https://ninenines.eu/docs/en/gun/1.0/manual/</link> <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> - <guid>http://ninenines.eu/docs/en/gun/1.0/manual/</guid> + <guid>https://ninenines.eu/docs/en/gun/1.0/manual/</guid> <description><div class="ulist"><ul>
<li>
<p>
@@ -489,10 +509,10 @@ <item> <title>Gun User Guide</title> - <link>http://ninenines.eu/docs/en/gun/1.0/guide/</link> + <link>https://ninenines.eu/docs/en/gun/1.0/guide/</link> <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> - <guid>http://ninenines.eu/docs/en/gun/1.0/guide/</guid> + <guid>https://ninenines.eu/docs/en/gun/1.0/guide/</guid> <description><div class="ulist"><ul>
<li>
<p>
@@ -530,10 +550,10 @@ <item> <title>HTTP status codes(7)</title> - <link>http://ninenines.eu/docs/en/cowboy/2.0/manual/http_status_codes/</link> + <link>https://ninenines.eu/docs/en/cowboy/2.0/manual/http_status_codes/</link> <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> - <guid>http://ninenines.eu/docs/en/cowboy/2.0/manual/http_status_codes/</guid> + <guid>https://ninenines.eu/docs/en/cowboy/2.0/manual/http_status_codes/</guid> <description><div class="sect1">
<h2 id="_name">Name</h2>
<div class="sectionbody">
@@ -804,10 +824,10 @@ client and the connection is closed.</p></div> <item> <title>Ranch Function Reference</title> - <link>http://ninenines.eu/docs/en/ranch/1.2/manual/</link> + <link>https://ninenines.eu/docs/en/ranch/1.2/manual/</link> <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> - <guid>http://ninenines.eu/docs/en/ranch/1.2/manual/</guid> + <guid>https://ninenines.eu/docs/en/ranch/1.2/manual/</guid> <description><div class="ulist"><ul>
<li>
<p>
@@ -845,10 +865,10 @@ client and the connection is closed.</p></div> <item> <title>Ranch User Guide</title> - <link>http://ninenines.eu/docs/en/ranch/1.2/guide/</link> + <link>https://ninenines.eu/docs/en/ranch/1.2/guide/</link> <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> - <guid>http://ninenines.eu/docs/en/ranch/1.2/guide/</guid> + <guid>https://ninenines.eu/docs/en/ranch/1.2/guide/</guid> <description><div class="ulist"><ul>
<li>
<p>
@@ -896,10 +916,10 @@ client and the connection is closed.</p></div> <item> <title>Request overview</title> - <link>http://ninenines.eu/docs/en/cowboy/2.0/guide/overview/</link> + <link>https://ninenines.eu/docs/en/cowboy/2.0/guide/overview/</link> <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> - <guid>http://ninenines.eu/docs/en/cowboy/2.0/guide/overview/</guid> + <guid>https://ninenines.eu/docs/en/cowboy/2.0/guide/overview/</guid> <description><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>
@@ -1048,10 +1068,10 @@ at this point, however.</p></div> <item> <title>cowboy(3)</title> - <link>http://ninenines.eu/docs/en/cowboy/2.0/manual/cowboy/</link> + <link>https://ninenines.eu/docs/en/cowboy/2.0/manual/cowboy/</link> <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> - <guid>http://ninenines.eu/docs/en/cowboy/2.0/manual/cowboy/</guid> + <guid>https://ninenines.eu/docs/en/cowboy/2.0/manual/cowboy/</guid> <description><div class="sect1">
<h2 id="_name">Name</h2>
<div class="sectionbody">
@@ -1066,207 +1086,276 @@ manipulating Ranch listeners.</p></div> </div>
</div>
<div class="sect1">
+<h2 id="_exports">Exports</h2>
+<div class="sectionbody">
+<div class="ulist"><ul>
+<li>
+<p>
+<a href="../cowboy.start_clear">cowboy:start_clear(3)</a> - Listen for connections using plain TCP
+</p>
+</li>
+<li>
+<p>
+<a href="../cowboy.start_tls">cowboy:start_tls(3)</a> - Listen for connections using TLS
+</p>
+</li>
+<li>
+<p>
+<a href="../cowboy.stop_listener">cowboy:stop_listener(3)</a> - Stop the given listener
+</p>
+</li>
+<li>
+<p>
+<a href="../cowboy.set_env">cowboy:set_env(3)</a> - Update a listener&#8217;s environment value
+</p>
+</li>
+</ul></div>
+</div>
+</div>
+<div class="sect1">
<h2 id="_types">Types</h2>
<div class="sectionbody">
<div class="sect2">
-<h3 id="_fields_field">fields() = [Field]</h3>
+<h3 id="_fields">fields()</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>
+<pre><tt><span style="font-weight: bold"><span style="color: #000000">fields</span></span>() <span style="color: #990000">::</span> [<span style="color: #009900">Name</span>
+ | {<span style="color: #009900">Name</span>, <span style="color: #009900">Constraints</span>}
+ | {<span style="color: #009900">Name</span>, <span style="color: #009900">Constraints</span>, <span style="color: #009900">Default</span>}]
+
+<span style="color: #009900">Name</span> <span style="color: #990000">::</span> <span style="font-weight: bold"><span style="color: #000080">atom</span></span>()
+<span style="color: #009900">Constraints</span> <span style="color: #990000">::</span> <span style="color: #009900">Constraint</span> | [<span style="color: #009900">Constraint</span>]
+<span style="color: #009900">Constraint</span> <span style="color: #990000">::</span> <span style="font-weight: bold"><span style="color: #000000">cowboy_constraints:constraint</span></span>()
+<span style="color: #009900">Default</span> <span style="color: #990000">::</span> <span style="font-weight: bold"><span style="color: #000000">any</span></span>()</tt></pre></div></div>
+<div class="paragraph"><p>Fields description for match operations.</p></div>
+<div class="paragraph"><p>This type is used in <a href="../cowboy_router">cowboy_router</a>
+for matching bindings and in the match functions found in
+<a href="../cowboy_req">cowboy_req</a>.</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>
+<h3 id="_http_headers">http_headers()</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="font-weight: bold"><span style="color: #000000">http_headers</span></span>() <span style="color: #990000">::</span> #{<span style="font-weight: bold"><span style="color: #000080">binary</span></span>() <span style="color: #990000">=&gt;</span> <span style="font-weight: bold"><span style="color: #000000">iodata</span></span>()}</tt></pre></div></div>
+<div class="paragraph"><p>HTTP headers.</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>
+<h3 id="_http_status">http_status()</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="font-weight: bold"><span style="color: #000000">http_status</span></span>() <span style="color: #990000">::</span> <span style="font-weight: bold"><span style="color: #000000">non_neg_integer</span></span>() | <span style="font-weight: bold"><span style="color: #000080">binary</span></span>()</tt></pre></div></div>
+<div class="paragraph"><p>HTTP response status.</p></div>
+<div class="paragraph"><p>A binary status can be used to set a reason phrase. Note
+however that HTTP/2 only sends the status code and drops
+the reason phrase entirely.</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>
+<h3 id="_http_version">http_version()</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="font-weight: bold"><span style="color: #000000">http_version</span></span>() <span style="color: #990000">::</span> <span style="color: #FF6600">'HTTP/2'</span> | <span style="color: #FF6600">'HTTP/1.1'</span> | <span style="color: #FF6600">'HTTP/1.0'</span></tt></pre></div></div>
<div class="paragraph"><p>HTTP version.</p></div>
+<div class="paragraph"><p>Note that semantically, HTTP/1.1 and HTTP/2 are equivalent.</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>
+<h3 id="_opts">opts()</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="font-weight: bold"><span style="color: #000000">opts</span></span>() <span style="color: #990000">::</span> <span style="font-weight: bold"><span style="color: #000000">map</span></span>()</tt></pre></div></div>
+<div class="paragraph"><p>Options for the HTTP/1.1, HTTP/2 and Websocket protocols.</p></div>
+<div class="paragraph"><p>The protocol options are in a map containing all the options for
+the different protocols that may be involved when connecting
+to the listener, including HTTP/1.1 and HTTP/2 but also
+subprotocols like Websocket.</p></div>
+<div class="paragraph"><p>The HTTP/1.1 options are documented in the
+<a href="../cowboy_http">cowboy_http(3)</a> manual;
+the HTTP/2 options in
+<a href="../cowboy_http">cowboy_http2(3)</a>;
+and the Websocket options in
+<a href="../cowboy_websocket">cowboy_websocket(3)</a>.</p></div>
</div>
</div>
</div>
<div class="sect1">
-<h2 id="_exports">Exports</h2>
+<h2 id="_see_also">See also</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>
+<div class="paragraph"><p><a href="../cowboy_app">cowboy(7)</a>,
+<a href="../ranch">ranch(3)</a></p></div>
+</div>
+</div>
+</description> + </item> + + <item> + <title>cowboy(7)</title> + <link>https://ninenines.eu/docs/en/cowboy/2.0/manual/cowboy_app/</link> + <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> + + <guid>https://ninenines.eu/docs/en/cowboy/2.0/manual/cowboy_app/</guid> + <description><div class="sect1">
+<h2 id="_name">Name</h2>
+<div class="sectionbody">
+<div class="paragraph"><p>cowboy - Small, fast, modern HTTP server for Erlang/OTP</p></div>
+</div>
+</div>
+<div class="sect1">
+<h2 id="_description">Description</h2>
+<div class="sectionbody">
+<div class="paragraph"><p>Cowboy is an HTTP server for Erlang/OTP with support for the
+HTTP/1.1, HTTP/2 and Websocket protocols.</p></div>
+<div class="paragraph"><p>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.</p></div>
+</div>
+</div>
+<div class="sect1">
+<h2 id="_modules">Modules</h2>
+<div class="sectionbody">
+<div class="paragraph"><p>Functions:</p></div>
+<div class="ulist"><ul>
+<li>
<p>
-Listener name.
+<a href="../cowboy">cowboy(3)</a> - Listener management
</p>
-</dd>
-<dt class="hdlist1">
-NbAcceptors = non_neg_integer()
-</dt>
-<dd>
+</li>
+<li>
<p>
-Number of acceptor processes.
+<a href="../cowboy_req">cowboy_req(3)</a> - Request and response
</p>
-</dd>
-<dt class="hdlist1">
-TransOpts = ranch_tcp:opts()
-</dt>
-<dd>
+</li>
+<li>
<p>
-TCP transport options.
+<a href="../cowboy_router">cowboy_router(3)</a> - Router
</p>
-</dd>
-<dt class="hdlist1">
-ProtoOpts = cowboy_protocol:opts()
-</dt>
-<dd>
+</li>
+</ul></div>
+<div class="paragraph"><p>Protocols:</p></div>
+<div class="ulist"><ul>
+<li>
<p>
-HTTP protocol options.
+<a href="../cowboy_http">cowboy_http(3)</a> - HTTP/1.1
</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>
+</li>
+<li>
<p>
-Listener name.
+<a href="../cowboy_http">cowboy_http2(3)</a> - HTTP/2
</p>
-</dd>
-<dt class="hdlist1">
-NbAcceptors = non_neg_integer()
-</dt>
-<dd>
+</li>
+<li>
<p>
-Number of acceptor processes.
+<a href="../cowboy_websocket">cowboy_websocket(3)</a> - Websocket
</p>
-</dd>
-<dt class="hdlist1">
-TransOpts = ranch_ssl:opts()
-</dt>
-<dd>
+</li>
+</ul></div>
+<div class="paragraph"><p>Handlers:</p></div>
+<div class="ulist"><ul>
+<li>
<p>
-SSL transport options.
+<a href="../cowboy_static">cowboy_static(3)</a> - Static file handler
</p>
-</dd>
-<dt class="hdlist1">
-ProtoOpts = cowboy_protocol:opts()
-</dt>
-<dd>
+</li>
+</ul></div>
+<div class="paragraph"><p>Behaviors:</p></div>
+<div class="ulist"><ul>
+<li>
<p>
-HTTP protocol options.
+<a href="../cowboy_handler">cowboy_handler(3)</a> - Plain HTTP handlers
</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>
+</li>
+<li>
<p>
-Listener name.
+<a href="../cowboy_loop">cowboy_loop(3)</a> - Loop handlers
</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>
+</li>
+<li>
<p>
-Listener name.
+<a href="../cowboy_middleware">cowboy_middleware(3)</a> - Middlewares
</p>
-</dd>
-<dt class="hdlist1">
-Name = atom()
-</dt>
-<dd>
+</li>
+<li>
<p>
-Name of environment value.
+<a href="../cowboy_rest">cowboy_rest(3)</a> - REST handlers
</p>
-</dd>
-<dt class="hdlist1">
-Value = any()
-</dt>
-<dd>
+</li>
+<li>
<p>
-Environment value.
+<a href="../cowboy_stream">cowboy_stream(3)</a> - Stream handlers
</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>
-</description> - </item> - - <item> - <title>cowboy(7)</title> - <link>http://ninenines.eu/docs/en/cowboy/2.0/manual/cowboy_app/</link> - <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> - - <guid>http://ninenines.eu/docs/en/cowboy/2.0/manual/cowboy_app/</guid> - <description><div class="sect1">
-<h2 id="_name">Name</h2>
-<div class="sectionbody">
-<div class="paragraph"><p>cowboy - Small, fast, modular HTTP server.</p></div>
+</li>
+<li>
+<p>
+<a href="../cowboy_sub_protocol">cowboy_sub_protocol(3)</a> - Sub protocols
+</p>
+</li>
+<li>
+<p>
+<a href="../cowboy_websocket">cowboy_websocket(3)</a> - Websocket handlers
+</p>
+</li>
+</ul></div>
+<div class="paragraph"><p>Middlewares:</p></div>
+<div class="ulist"><ul>
+<li>
+<p>
+<a href="../cowboy_router">cowboy_router(3)</a> - Router middleware
+</p>
+</li>
+<li>
+<p>
+<a href="../cowboy_handler">cowboy_handler(3)</a> - Handler middleware
+</p>
+</li>
+</ul></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 class="ulist"><ul>
+<li>
+<p>
+<a href="../ranch">ranch(7)</a> - Socket acceptor pool for TCP protocols
+</p>
+</li>
+<li>
+<p>
+<a href="../cowlib">cowlib(7)</a> - Support library for manipulating Web protocols
+</p>
+</li>
+<li>
+<p>
+ssl - Secure communication over sockets
+</p>
+</li>
+<li>
+<p>
+crypto - Crypto functions
+</p>
+</li>
+</ul></div>
+<div class="paragraph"><p>All these applications must be started before the <code>cowboy</code>
+application. To start Cowboy and all dependencies at once:</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: #FF6600">ok</span>, <span style="color: #990000">_</span>} <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">application:ensure_all_started</span></span>(<span style="color: #FF6600">cowboy</span>)<span style="color: #990000">.</span></tt></pre></div></div>
</div>
</div>
<div class="sect1">
@@ -1276,636 +1365,571 @@ These are started automatically if they weren&#8217;t before.</p></ environment configuration parameters.</p></div>
</div>
</div>
+<div class="sect1">
+<h2 id="_see_also">See also</h2>
+<div class="sectionbody">
+<div class="paragraph"><p><a href="../ranch">ranch(7)</a>,
+<a href="../cowlib">cowlib(7)</a></p></div>
+</div>
+</div>
</description> </item> <item> - <title>cowboy_handler(3)</title> - <link>http://ninenines.eu/docs/en/cowboy/2.0/manual/cowboy_handler/</link> + <title>cowboy:set_env(3)</title> + <link>https://ninenines.eu/docs/en/cowboy/2.0/manual/cowboy.set_env/</link> <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> - <guid>http://ninenines.eu/docs/en/cowboy/2.0/manual/cowboy_handler/</guid> + <guid>https://ninenines.eu/docs/en/cowboy/2.0/manual/cowboy.set_env/</guid> <description><div class="sect1">
<h2 id="_name">Name</h2>
<div class="sectionbody">
-<div class="paragraph"><p>cowboy_handler - handler middleware and behaviour</p></div>
+<div class="paragraph"><p>cowboy:set_env - Update a listener&#8217;s environment value</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="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">set_env</span></span>(<span style="color: #009900">Name</span> <span style="color: #990000">::</span> <span style="font-weight: bold"><span style="color: #000000">ranch:ref</span></span>(),
+ <span style="color: #009900">Key</span> <span style="color: #990000">::</span> <span style="font-weight: bold"><span style="color: #000080">atom</span></span>(),
+ <span style="color: #009900">Value</span> <span style="color: #990000">::</span> <span style="font-weight: bold"><span style="color: #000000">any</span></span>())
+ <span style="color: #990000">-&gt;</span> <span style="color: #FF6600">ok</span></tt></pre></div></div>
+<div class="paragraph"><p>Set or update an environment value for a previously started
+listener.</p></div>
+<div class="paragraph"><p>This is most useful for updating the routes dynamically,
+without having to restart the listener.</p></div>
+<div class="paragraph"><p>The new value will only be available to new connections.
+Pre-existing connections will still use the old value.</p></div>
+</div>
+</div>
+<div class="sect1">
+<h2 id="_arguments">Arguments</h2>
+<div class="sectionbody">
<div class="dlist"><dl>
<dt class="hdlist1">
-handler = module()
+Name
</dt>
<dd>
<p>
-Handler to be executed.
+The name of the listener to update.
</p>
+<div class="paragraph"><p>The name of the listener is the first argument given to the
+<a href="../cowboy.start_clear">cowboy:start_clear(3)</a>,
+<a href="../cowboy.start_tls">cowboy:start_tls(3)</a> or
+<a href="../ranch.start_listener">ranch:start_listener(3)</a> function.</p></div>
</dd>
<dt class="hdlist1">
-handler_opts = any()
+Key
</dt>
<dd>
<p>
-Options to be passed to the handler.
+The key in the environment map. Common keys include <code>dispatch</code>
+and <code>middlewares</code>.
</p>
</dd>
-</dl></div>
-<div class="paragraph"><p>Environment output:</p></div>
-<div class="dlist"><dl>
<dt class="hdlist1">
-result = ok
+Value
</dt>
<dd>
<p>
-Result of the request.
+The new value.
</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 class="paragraph"><p>The type of the value differs depending on the key.</p></div>
</div>
</div>
<div class="sect1">
-<h2 id="_terminate_reasons">Terminate reasons</h2>
+<h2 id="_return_value">Return value</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 class="paragraph"><p>The atom <code>ok</code> is returned on success.</p></div>
+<div class="paragraph"><p>An <code>exit:badarg</code> exception is thrown when the listener does
+not exist.</p></div>
</div>
</div>
<div class="sect1">
-<h2 id="_callbacks">Callbacks</h2>
+<h2 id="_changelog">Changelog</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>
+<div class="ulist"><ul>
+<li>
<p>
-Timeout passed to the sub-protocol, when applicable.
+<strong>1.0</strong>: Function introduced.
</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>
+</li>
+</ul></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 class="sect1">
+<h2 id="_examples">Examples</h2>
+<div class="sectionbody">
+<div class="listingblock">
+<div class="title">Update a listener&#8217;s routes</div>
+<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">Dispatch</span> <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">cowboy_router:compile</span></span>([
+ {<span style="color: #FF6600">'_'</span>, [
+ {<span style="color: #FF0000">"/"</span>, <span style="color: #FF6600">toppage_h</span>, []},
+ {<span style="color: #FF0000">"/ws"</span>, <span style="color: #FF6600">websocket_h</span>, []}
+ ]}
+]),
+
+<span style="font-weight: bold"><span style="color: #000000">cowboy:set_env</span></span>(<span style="color: #FF6600">example</span>, <span style="color: #FF6600">dispatch</span>, <span style="color: #009900">Dispatch</span>)<span style="color: #990000">.</span></tt></pre></div></div>
</div>
</div>
<div class="sect1">
-<h2 id="_exports">Exports</h2>
+<h2 id="_see_also">See also</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 class="paragraph"><p><a href="../cowboy">cowboy(3)</a>,
+<a href="../cowboy.start_clear">cowboy:start_clear(3)</a>,
+<a href="../cowboy.start_tls">cowboy:start_tls(3)</a>,
+<a href="../ranch.set_protocol_options">ranch:set_protocol_options(3)</a></p></div>
</div>
</div>
</description> </item> <item> - <title>cowboy_loop(3)</title> - <link>http://ninenines.eu/docs/en/cowboy/2.0/manual/cowboy_loop/</link> + <title>cowboy:start_clear(3)</title> + <link>https://ninenines.eu/docs/en/cowboy/2.0/manual/cowboy.start_clear/</link> <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> - <guid>http://ninenines.eu/docs/en/cowboy/2.0/manual/cowboy_loop/</guid> + <guid>https://ninenines.eu/docs/en/cowboy/2.0/manual/cowboy.start_clear/</guid> <description><div class="sect1">
<h2 id="_name">Name</h2>
<div class="sectionbody">
-<div class="paragraph"><p>cowboy_loop - loop handlers</p></div>
+<div class="paragraph"><p>cowboy:start_clear - Listen for connections using plain TCP</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 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">start_clear</span></span>(<span style="color: #009900">Name</span> <span style="color: #990000">::</span> <span style="font-weight: bold"><span style="color: #000000">ranch:ref</span></span>(),
+ <span style="color: #009900">NumAcceptors</span> <span style="color: #990000">::</span> <span style="font-weight: bold"><span style="color: #000000">non_neg_integer</span></span>(),
+ <span style="color: #009900">TransportOpts</span> <span style="color: #990000">::</span> <span style="font-weight: bold"><span style="color: #000000">ranch_tcp:opts</span></span>(),
+ <span style="color: #009900">ProtocolOpts</span> <span style="color: #990000">::</span> <span style="font-weight: bold"><span style="color: #000000">opts</span></span>())
+ <span style="color: #990000">-&gt;</span> {<span style="color: #FF6600">ok</span>, <span style="color: #009900">ListenerPid</span> <span style="color: #990000">::</span> <span style="font-weight: bold"><span style="color: #000080">pid</span></span>()}
+ | {<span style="color: #FF6600">error</span>, <span style="font-weight: bold"><span style="color: #000000">any</span></span>()}</tt></pre></div></div>
+<div class="paragraph"><p>Start listening for connections over a clear TCP channel.</p></div>
+<div class="paragraph"><p>Both HTTP/1.1 and HTTP/2 are supported on this listener.
+HTTP/2 has two methods of establishing a connection over
+a clear TCP channel. Both the upgrade and the prior knowledge
+methods are supported.</p></div>
</div>
</div>
<div class="sect1">
-<h2 id="_terminate_reasons">Terminate reasons</h2>
+<h2 id="_arguments">Arguments</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}
+Name
</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.
+The listener name is used to refer to this listener in
+future calls, for example when stopping it or when
+updating the routes defined.
</p>
+<div class="paragraph"><p>It can be any Erlang term. An atom is generally good enough,
+for example <code>api</code>, <code>my_app_clear</code> or <code>my_app_tls</code>.</p></div>
</dd>
<dt class="hdlist1">
-{error, overflow}
+NumAcceptors
</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>
+The number of acceptors is the number of processes that
+will accept connections. Tweak this value to improve the
+accept rate for incoming connections.
+</p>
+<div class="paragraph"><p>The ideal value is between 10 and 100 on most systems.
+Larger values may have the opposite effect and reduce the
+accept rate. It&#8217;s generally safe to start with a value of
+100 (or 10 on low memory systems). Then, when accept rates
+become a concern, measure the performance and update the
+value accordingly.</p></div>
+<div class="paragraph"><p>This value is unrelated to the maximum number of concurrent
+connections.</p></div>
</dd>
<dt class="hdlist1">
-{error, closed}
+TransportOpts
</dt>
<dd>
<p>
- The socket has been closed brutally without a close frame being
- received first.
+The transport options are where the TCP options, including
+the listener&#8217;s port number, are defined. Transport options
+are provided as a list of keys and values, for example
+<code>[{port, 8080}]</code>.
</p>
+<div class="paragraph"><p>The available options are documented in the
+<a href="../ranch_tcp">ranch_tcp(3)</a> manual.</p></div>
</dd>
<dt class="hdlist1">
-{error, Reason}
+ProtocolOpts
</dt>
<dd>
<p>
- A socket error ocurred.
-</p>
+The protocol options are in a map containing all the options for
+the different protocols that may be involved when connecting
+to the listener, including HTTP/1.1 and HTTP/2 but also
+subprotocols like Websocket.
+</p>
+<div class="paragraph"><p>The HTTP/1.1 options are documented in the
+<a href="../cowboy_http">cowboy_http(3)</a> manual;
+the HTTP/2 options in
+<a href="../cowboy_http">cowboy_http2(3)</a>;
+and the Websocket options in
+<a href="../cowboy_websocket">cowboy_websocket(3)</a>.</p></div>
</dd>
</dl></div>
</div>
</div>
<div class="sect1">
-<h2 id="_callbacks">Callbacks</h2>
+<h2 id="_return_value">Return value</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>
+<div class="paragraph"><p>An ok tuple is returned on success. It contains the pid of
+the top-level supervisor for the listener.</p></div>
+<div class="paragraph"><p>An error tuple is returned on error. The error reason may
+be any Erlang term.</p></div>
+<div class="paragraph"><p>A common error is <code>eaddrinuse</code>. It indicates that the port
+configured for Cowboy is already in use.</p></div>
+</div>
+</div>
+<div class="sect1">
+<h2 id="_changelog">Changelog</h2>
+<div class="sectionbody">
+<div class="ulist"><ul>
+<li>
<p>
-The Req object.
+<strong>2.0</strong>: HTTP/2 support added.
</p>
-</dd>
-<dt class="hdlist1">
-State = any()
-</dt>
-<dd>
+</li>
+<li>
<p>
-Handler state.
+<strong>2.0</strong>: Function introduced. Replaces <code>cowboy:start_http/4</code>.
</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>
+</li>
+</ul></div>
+</div>
+</div>
+<div class="sect1">
+<h2 id="_examples">Examples</h2>
+<div class="sectionbody">
+<div class="listingblock">
+<div class="title">Start a listener</div>
+<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">Dispatch</span> <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">cowboy_router:compile</span></span>([
+ {<span style="color: #FF6600">'_'</span>, [
+ {<span style="color: #FF0000">"/"</span>, <span style="color: #FF6600">toppage_h</span>, []}
+ ]}
+]),
+
+{<span style="color: #FF6600">ok</span>, <span style="color: #990000">_</span>} <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">cowboy:start_clear</span></span>(<span style="color: #FF6600">example</span>, <span style="color: #993399">100</span>, [{<span style="color: #FF6600">port</span>, <span style="color: #993399">8080</span>}], #{
+ <span style="color: #0000FF">env</span> <span style="color: #990000">=&gt;</span> #{<span style="color: #0000FF">dispatch</span> <span style="color: #990000">=&gt;</span> <span style="color: #009900">Dispatch</span>}
+})<span style="color: #990000">.</span></tt></pre></div></div>
+<div class="listingblock">
+<div class="title">Start a listener on a random port</div>
+<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">Name</span> <span style="color: #990000">=</span> <span style="color: #FF6600">example</span>,
+
+{<span style="color: #FF6600">ok</span>, <span style="color: #990000">_</span>} <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">cowboy:start_clear</span></span>(<span style="color: #009900">Name</span>, <span style="color: #993399">100</span>, [], #{
+ <span style="color: #0000FF">env</span> <span style="color: #990000">=&gt;</span> #{<span style="color: #0000FF">dispatch</span> <span style="color: #990000">=&gt;</span> <span style="color: #009900">Dispatch</span>}
+}),
+
+<span style="color: #009900">Port</span> <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">ranch:get_port</span></span>(<span style="color: #009900">Name</span>)<span style="color: #990000">.</span></tt></pre></div></div>
+</div>
</div>
+<div class="sect1">
+<h2 id="_see_also">See also</h2>
+<div class="sectionbody">
+<div class="paragraph"><p><a href="../cowboy">cowboy(3)</a>,
+<a href="../cowboy.start_tls">cowboy:start_tls(3)</a>,
+<a href="../ranch">ranch(3)</a></p></div>
</div>
</div>
</description> </item> <item> - <title>cowboy_middleware(3)</title> - <link>http://ninenines.eu/docs/en/cowboy/2.0/manual/cowboy_middleware/</link> + <title>cowboy:start_tls(3)</title> + <link>https://ninenines.eu/docs/en/cowboy/2.0/manual/cowboy.start_tls/</link> <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> - <guid>http://ninenines.eu/docs/en/cowboy/2.0/manual/cowboy_middleware/</guid> + <guid>https://ninenines.eu/docs/en/cowboy/2.0/manual/cowboy.start_tls/</guid> <description><div class="sect1">
<h2 id="_name">Name</h2>
<div class="sectionbody">
-<div class="paragraph"><p>cowboy_middleware - behaviour for middlewares</p></div>
+<div class="paragraph"><p>cowboy:start_tls - Listen for connections using TLS</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 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">start_tls</span></span>(<span style="color: #009900">Name</span> <span style="color: #990000">::</span> <span style="font-weight: bold"><span style="color: #000000">ranch:ref</span></span>(),
+ <span style="color: #009900">NumAcceptors</span> <span style="color: #990000">::</span> <span style="font-weight: bold"><span style="color: #000000">non_neg_integer</span></span>(),
+ <span style="color: #009900">TransportOpts</span> <span style="color: #990000">::</span> <span style="font-weight: bold"><span style="color: #000000">ranch_ssl:opts</span></span>(),
+ <span style="color: #009900">ProtocolOpts</span> <span style="color: #990000">::</span> <span style="font-weight: bold"><span style="color: #000000">opts</span></span>())
+ <span style="color: #990000">-&gt;</span> {<span style="color: #FF6600">ok</span>, <span style="color: #009900">ListenerPid</span> <span style="color: #990000">::</span> <span style="font-weight: bold"><span style="color: #000080">pid</span></span>()}
+ | {<span style="color: #FF6600">error</span>, <span style="font-weight: bold"><span style="color: #000000">any</span></span>()}</tt></pre></div></div>
+<div class="paragraph"><p>Start listening for connections over a secure TLS channel.</p></div>
+<div class="paragraph"><p>Both HTTP/1.1 and HTTP/2 are supported on this listener.
+The ALPN TLS extension must be used to initiate an HTTP/2
+connection.</p></div>
</div>
</div>
<div class="sect1">
-<h2 id="_callbacks">Callbacks</h2>
+<h2 id="_arguments">Arguments</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()
+Name
</dt>
<dd>
<p>
-The Req object.
+The listener name is used to refer to this listener in
+future calls, for example when stopping it or when
+updating the routes defined.
</p>
+<div class="paragraph"><p>It can be any Erlang term. An atom is generally good enough,
+for example <code>api</code>, <code>my_app_clear</code> or <code>my_app_tls</code>.</p></div>
</dd>
<dt class="hdlist1">
-Env = env()
+NumAcceptors
</dt>
<dd>
<p>
-The request environment.
-</p>
+The number of acceptors is the number of processes that
+will accept connections. Tweak this value to improve the
+accept rate for incoming connections.
+</p>
+<div class="paragraph"><p>The ideal value is between 10 and 100 on most systems.
+Larger values may have the opposite effect and reduce the
+accept rate. It&#8217;s generally safe to start with a value of
+100 (or 10 on low memory systems). Then, when accept rates
+become a concern, measure the performance and update the
+value accordingly.</p></div>
+<div class="paragraph"><p>This value is unrelated to the maximum number of concurrent
+connections.</p></div>
</dd>
<dt class="hdlist1">
-Module = module()
+TransportOpts
</dt>
<dd>
<p>
-MFA to call when resuming the process.
+The transport options are where the TCP options, including
+the listener&#8217;s port number, are defined. They also contain
+the TLS options, like the server&#8217;s certificate. Transport options
+are provided as a list of keys and values, for example
+<code>[{port, 8443}, {certfile, "path/to/cert.pem"}]</code>.
</p>
+<div class="paragraph"><p>The available options are documented in the
+<a href="../ranch_ssl">ranch_ssl(3)</a> manual.</p></div>
</dd>
<dt class="hdlist1">
-Function = atom()
+ProtocolOpts
</dt>
<dd>
<p>
-MFA to call when resuming the process.
-</p>
+The protocol options are in a map containing all the options for
+the different protocols that may be involved when connecting
+to the listener, including HTTP/1.1 and HTTP/2 but also
+subprotocols like Websocket.
+</p>
+<div class="paragraph"><p>The HTTP/1.1 options are documented in the
+<a href="../cowboy_http">cowboy_http(3)</a> manual;
+the HTTP/2 options in
+<a href="../cowboy_http">cowboy_http2(3)</a>;
+and the Websocket options in
+<a href="../cowboy_websocket">cowboy_websocket(3)</a>.</p></div>
</dd>
-<dt class="hdlist1">
-Args = [any()]
-</dt>
-<dd>
+</dl></div>
+</div>
+</div>
+<div class="sect1">
+<h2 id="_return_value">Return value</h2>
+<div class="sectionbody">
+<div class="paragraph"><p>An ok tuple is returned on success. It contains the pid of
+the top-level supervisor for the listener.</p></div>
+<div class="paragraph"><p>An error tuple is returned on error. The error reason may
+be any Erlang term.</p></div>
+<div class="paragraph"><p>A common error is <code>eaddrinuse</code>. It indicates that the port
+configured for Cowboy is already in use.</p></div>
+</div>
+</div>
+<div class="sect1">
+<h2 id="_changelog">Changelog</h2>
+<div class="sectionbody">
+<div class="ulist"><ul>
+<li>
<p>
-MFA to call when resuming the process.
+<strong>2.0</strong>: HTTP/2 support added.
</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>
+</li>
+<li>
+<p>
+<strong>2.0</strong>: Function introduced. Replaces <code>cowboy:start_https/4</code>.
+</p>
+</li>
+</ul></div>
</div>
</div>
+<div class="sect1">
+<h2 id="_examples">Examples</h2>
+<div class="sectionbody">
+<div class="listingblock">
+<div class="title">Start a listener</div>
+<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">Dispatch</span> <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">cowboy_router:compile</span></span>([
+ {<span style="color: #FF6600">'_'</span>, [
+ {<span style="color: #FF0000">"/"</span>, <span style="color: #FF6600">toppage_h</span>, []}
+ ]}
+]),
+
+{<span style="color: #FF6600">ok</span>, <span style="color: #990000">_</span>} <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">cowboy:start_tls</span></span>(<span style="color: #FF6600">example</span>, <span style="color: #993399">100</span>, [
+ {<span style="color: #FF6600">port</span>, <span style="color: #993399">8443</span>},
+ {<span style="color: #FF6600">cert</span>, <span style="color: #FF0000">"path/to/cert.pem"</span>}
+], #{
+ <span style="color: #0000FF">env</span> <span style="color: #990000">=&gt;</span> #{<span style="color: #0000FF">dispatch</span> <span style="color: #990000">=&gt;</span> <span style="color: #009900">Dispatch</span>}
+})<span style="color: #990000">.</span></tt></pre></div></div>
+<div class="listingblock">
+<div class="title">Start a listener on a random port</div>
+<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">Name</span> <span style="color: #990000">=</span> <span style="color: #FF6600">example</span>,
+
+{<span style="color: #FF6600">ok</span>, <span style="color: #990000">_</span>} <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">cowboy:start_tls</span></span>(<span style="color: #009900">Name</span>, <span style="color: #993399">100</span>, [
+ {<span style="color: #FF6600">cert</span>, <span style="color: #FF0000">"path/to/cert.pem"</span>}
+], #{
+ <span style="color: #0000FF">env</span> <span style="color: #990000">=&gt;</span> #{<span style="color: #0000FF">dispatch</span> <span style="color: #990000">=&gt;</span> <span style="color: #009900">Dispatch</span>}
+}),
+
+<span style="color: #009900">Port</span> <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">ranch:get_port</span></span>(<span style="color: #009900">Name</span>)<span style="color: #990000">.</span></tt></pre></div></div>
+</div>
+</div>
+<div class="sect1">
+<h2 id="_see_also">See also</h2>
+<div class="sectionbody">
+<div class="paragraph"><p><a href="../cowboy">cowboy(3)</a>,
+<a href="../cowboy.start_clear">cowboy:start_clear(3)</a>,
+<a href="../ranch">ranch(3)</a></p></div>
+</div>
</div>
</description> </item> <item> - <title>cowboy_protocol(3)</title> - <link>http://ninenines.eu/docs/en/cowboy/2.0/manual/cowboy_protocol/</link> + <title>cowboy:stop_listener(3)</title> + <link>https://ninenines.eu/docs/en/cowboy/2.0/manual/cowboy.stop_listener/</link> <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> - <guid>http://ninenines.eu/docs/en/cowboy/2.0/manual/cowboy_protocol/</guid> + <guid>https://ninenines.eu/docs/en/cowboy/2.0/manual/cowboy.stop_listener/</guid> <description><div class="sect1">
<h2 id="_name">Name</h2>
<div class="sectionbody">
-<div class="paragraph"><p>cowboy_protocol - HTTP protocol</p></div>
+<div class="paragraph"><p>cowboy:stop_listener - Stop the given listener</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>
+<pre><tt><span style="font-weight: bold"><span style="color: #000000">stop_listener</span></span>(<span style="color: #009900">Name</span> <span style="color: #990000">::</span> <span style="font-weight: bold"><span style="color: #000000">ranch:ref</span></span>())
+ <span style="color: #990000">-&gt;</span> <span style="color: #FF6600">ok</span> | {<span style="color: #FF6600">error</span>, <span style="color: #FF6600">not_found</span>}<span style="color: #990000">.</span></tt></pre></div></div>
+<div class="paragraph"><p>Stop a previously started listener.</p></div>
+<div class="paragraph"><p>Alias of <a href="../ranch.stop_listener">ranch:stop_listener(3)</a>.</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>
+<div class="sect1">
+<h2 id="_arguments">Arguments</h2>
+<div class="sectionbody">
<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}])
+Name
</dt>
<dd>
<p>
- Initial middleware environment.
+The name of the listener to be stopped.
</p>
+<div class="paragraph"><p>The name of the listener is the first argument given to the
+<a href="../cowboy.start_clear">cowboy:start_clear(3)</a>,
+<a href="../cowboy.start_tls">cowboy:start_tls(3)</a> or
+<a href="../ranch.start_listener">ranch:start_listener(3)</a> function.</p></div>
</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>
+</dl></div>
+</div>
+</div>
+<div class="sect1">
+<h2 id="_return_value">Return value</h2>
+<div class="sectionbody">
+<div class="paragraph"><p>The atom <code>ok</code> is returned on success.</p></div>
+<div class="paragraph"><p>The <code>{error, not_found}</code> tuple is returned when the listener
+does not exist.</p></div>
+</div>
+</div>
+<div class="sect1">
+<h2 id="_changelog">Changelog</h2>
+<div class="sectionbody">
+<div class="ulist"><ul>
+<li>
<p>
- Time in ms with no requests before Cowboy closes the connection.
+<strong>1.0</strong>: Function introduced.
</p>
-</dd>
-</dl></div>
+</li>
+</ul></div>
+</div>
+</div>
+<div class="sect1">
+<h2 id="_examples">Examples</h2>
+<div class="sectionbody">
+<div class="listingblock">
+<div class="title">Stop a listener</div>
+<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: #0000FF">ok</span> <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">cowboy:stop_listener</span></span>(<span style="color: #FF6600">example</span>)<span style="color: #990000">.</span></tt></pre></div></div>
</div>
</div>
+<div class="sect1">
+<h2 id="_see_also">See also</h2>
+<div class="sectionbody">
+<div class="paragraph"><p><a href="../cowboy">cowboy(3)</a>,
+<a href="../cowboy.start_clear">cowboy:start_clear(3)</a>,
+<a href="../cowboy.start_tls">cowboy:start_tls(3)</a>,
+<a href="../ranch">ranch(3)</a>,
+<a href="../ranch.start_listener">ranch:start_listener(3)</a></p></div>
+</div>
</div>
</description> </item> |