summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--docs/en/cowboy/2.0/guide/architecture.asciidoc48
-rw-r--r--docs/en/cowboy/2.0/guide/architecture/index.html207
-rw-r--r--docs/en/cowboy/2.0/guide/broken_clients.asciidoc62
-rw-r--r--docs/en/cowboy/2.0/guide/broken_clients/index.html203
-rw-r--r--docs/en/cowboy/2.0/guide/constraints.asciidoc74
-rw-r--r--docs/en/cowboy/2.0/guide/constraints/index.html72
-rw-r--r--docs/en/cowboy/2.0/guide/flow_diagram.asciidoc109
-rw-r--r--docs/en/cowboy/2.0/guide/flow_diagram/index.html123
-rw-r--r--docs/en/cowboy/2.0/guide/handlers.asciidoc11
-rw-r--r--docs/en/cowboy/2.0/guide/handlers/index.html10
-rw-r--r--docs/en/cowboy/2.0/guide/hooks.asciidoc46
-rw-r--r--docs/en/cowboy/2.0/guide/hooks/index.html201
-rw-r--r--docs/en/cowboy/2.0/guide/http_req_resp.pngbin28370 -> 20713 bytes
-rw-r--r--docs/en/cowboy/2.0/guide/http_req_resp.svg557
-rw-r--r--docs/en/cowboy/2.0/guide/index.html7
-rw-r--r--docs/en/cowboy/2.0/guide/middlewares/index.html4
-rw-r--r--docs/en/cowboy/2.0/guide/migrating_from_1.0.asciidoc2
-rw-r--r--docs/en/cowboy/2.0/guide/migrating_from_1.0/index.html6
-rw-r--r--docs/en/cowboy/2.0/guide/overview.asciidoc150
-rw-r--r--docs/en/cowboy/2.0/guide/overview/index.html297
-rw-r--r--docs/en/cowboy/2.0/guide/specs.asciidoc1
-rw-r--r--docs/en/cowboy/2.0/guide/specs/index.html9
-rw-r--r--docs/en/cowboy/2.0/guide/streams.asciidoc68
-rw-r--r--docs/en/cowboy/2.0/guide/streams/index.html74
-rw-r--r--docs/en/cowboy/2.0/guide/sub_protocols.asciidoc73
-rw-r--r--docs/en/cowboy/2.0/guide/sub_protocols/index.html227
-rw-r--r--docs/en/cowboy/2.0/manual/cowboy_sub_protocol/index.html221
-rw-r--r--docs/index.xml7
-rw-r--r--donate/index.html12
-rw-r--r--index.html12
-rw-r--r--services/index.html12
-rw-r--r--sitemap.xml24
32 files changed, 730 insertions, 2199 deletions
diff --git a/docs/en/cowboy/2.0/guide/architecture.asciidoc b/docs/en/cowboy/2.0/guide/architecture.asciidoc
deleted file mode 100644
index 416ef36b..00000000
--- a/docs/en/cowboy/2.0/guide/architecture.asciidoc
+++ /dev/null
@@ -1,48 +0,0 @@
-[[architecture]]
-== Architecture
-
-Cowboy is a lightweight HTTP server.
-
-It is built on top of Ranch. Please see the Ranch guide for more
-information.
-
-=== One process per connection
-
-It uses only one process per connection. The process where your
-code runs is the process controlling the socket. Using one process
-instead of two allows for lower memory usage.
-
-Because there can be more than one request per connection with the
-keepalive feature of HTTP/1.1, that means the same process will be
-used to handle many requests.
-
-Because of this, you are expected to make sure your process cleans
-up before terminating the handling of the current request. This may
-include cleaning up the process dictionary, timers, monitoring and
-more.
-
-=== Binaries
-
-It uses binaries. Binaries are more efficient than lists for
-representing strings because they take less memory space. Processing
-performance can vary depending on the operation. Binaries are known
-for generally getting a great boost if the code is compiled natively.
-Please see the HiPE documentation for more details.
-
-=== Date header
-
-Because querying for the current date and time can be expensive,
-Cowboy generates one `Date` header value every second, shares it
-to all other processes, which then simply copy it in the response.
-This allows compliance with HTTP/1.1 with no actual performance loss.
-
-=== Max connections
-
-By default the maximum number of active connections is set to a
-generally accepted big enough number. This is meant to prevent having
-too many processes performing potentially heavy work and slowing
-everything else down, or taking up all the memory.
-
-Disabling this feature, by setting the `{max_connections, infinity}`
-protocol option, would give you greater performance when you are
-only processing short-lived requests.
diff --git a/docs/en/cowboy/2.0/guide/architecture/index.html b/docs/en/cowboy/2.0/guide/architecture/index.html
deleted file mode 100644
index cf166dfb..00000000
--- a/docs/en/cowboy/2.0/guide/architecture/index.html
+++ /dev/null
@@ -1,207 +0,0 @@
-<!DOCTYPE html>
-<html lang="en">
-
-<head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <meta name="description" content="">
- <meta name="author" content="Loïc Hoguin based on a design from (Soft10) Pol Cámara">
-
- <meta name="generator" content="Hugo 0.17" />
-
- <title>Nine Nines: Architecture</title>
-
- <link href='https://fonts.googleapis.com/css?family=Open+Sans:400,700,400italic' rel='stylesheet' type='text/css'>
- <link href="/css/99s.css?r=1" rel="stylesheet">
-
- <link rel="shortcut icon" href="/img/ico/favicon.ico">
- <link rel="apple-touch-icon-precomposed" sizes="114x114" href="/img/ico/apple-touch-icon-114.png">
- <link rel="apple-touch-icon-precomposed" sizes="72x72" href="/img/ico/apple-touch-icon-72.png">
- <link rel="apple-touch-icon-precomposed" href="/img/ico/apple-touch-icon-57.png">
-
-
-</head>
-
-
-<body class="">
- <header id="page-head">
- <div id="topbar" class="container">
- <div class="row">
- <div class="span2">
- <h1 id="logo"><a href="/" title="99s">99s</a></h1>
- </div>
- <div class="span10">
-
- <div id="side-header">
- <nav>
- <ul>
- <li><a title="Hear my thoughts" href="/articles">Articles</a></li>
- <li><a title="Watch my talks" href="/talks">Talks</a></li>
- <li class="active"><a title="Read the docs" href="/docs">Documentation</a></li>
- <li><a title="Request my services" href="/services">Consulting & Training</a></li>
- </ul>
- </nav>
- <ul id="social">
- <li>
- <a href="https://github.com/ninenines" title="Check my Github repositories"><img src="/img/ico_github.png" data-hover="/img/ico_github_alt.png" alt="Github"></a>
- </li>
- <li>
- <a title="Keep in touch!" href="http://twitter.com/lhoguin"><img src="/img/ico_microblog.png" data-hover="/img/ico_microblog_alt.png"></a>
- </li>
- <li>
- <a title="Contact me" href="mailto:[email protected]"><img src="/img/ico_mail.png" data-hover="/img/ico_mail_alt.png"></a>
- </li>
- </ul>
- </div>
- </div>
- </div>
- </div>
-
-
-</header>
-
-<div id="contents" class="two_col">
-<div class="container">
-<div class="row">
-<div id="docs" class="span9 maincol">
-
-<h1 class="lined-header"><span>Architecture</span></h1>
-
-<div class="paragraph"><p>Cowboy is a lightweight HTTP server.</p></div>
-<div class="paragraph"><p>It is built on top of Ranch. Please see the Ranch guide for more
-information.</p></div>
-<div class="sect1">
-<h2 id="_one_process_per_connection">One process per connection</h2>
-<div class="sectionbody">
-<div class="paragraph"><p>It uses only one process per connection. The process where your
-code runs is the process controlling the socket. Using one process
-instead of two allows for lower memory usage.</p></div>
-<div class="paragraph"><p>Because there can be more than one request per connection with the
-keepalive feature of HTTP/1.1, that means the same process will be
-used to handle many requests.</p></div>
-<div class="paragraph"><p>Because of this, you are expected to make sure your process cleans
-up before terminating the handling of the current request. This may
-include cleaning up the process dictionary, timers, monitoring and
-more.</p></div>
-</div>
-</div>
-<div class="sect1">
-<h2 id="_binaries">Binaries</h2>
-<div class="sectionbody">
-<div class="paragraph"><p>It uses binaries. Binaries are more efficient than lists for
-representing strings because they take less memory space. Processing
-performance can vary depending on the operation. Binaries are known
-for generally getting a great boost if the code is compiled natively.
-Please see the HiPE documentation for more details.</p></div>
-</div>
-</div>
-<div class="sect1">
-<h2 id="_date_header">Date header</h2>
-<div class="sectionbody">
-<div class="paragraph"><p>Because querying for the current date and time can be expensive,
-Cowboy generates one <code>Date</code> header value every second, shares it
-to all other processes, which then simply copy it in the response.
-This allows compliance with HTTP/1.1 with no actual performance loss.</p></div>
-</div>
-</div>
-<div class="sect1">
-<h2 id="_max_connections">Max connections</h2>
-<div class="sectionbody">
-<div class="paragraph"><p>By default the maximum number of active connections is set to a
-generally accepted big enough number. This is meant to prevent having
-too many processes performing potentially heavy work and slowing
-everything else down, or taking up all the memory.</p></div>
-<div class="paragraph"><p>Disabling this feature, by setting the <code>{max_connections, infinity}</code>
-protocol option, would give you greater performance when you are
-only processing short-lived requests.</p></div>
-</div>
-</div>
-
-
-
-
-
-
-
- <nav style="margin:1em 0">
-
- <a style="float:left" href="https://ninenines.eu/docs/en/cowboy/2.0/guide/specs/">
- HTTP and other specifications
- </a>
-
-
-
- <a style="float:right" href="https://ninenines.eu/docs/en/cowboy/2.0/guide/broken_clients/">
- Dealing with broken clients
- </a>
-
- </nav>
-
-
-
-
-</div>
-
-<div class="span3 sidecol">
-
-
-<h3>
- Cowboy
- 2.0
-
- User Guide
-</h3>
-
-<ul>
-
- <li><a href="/docs/en/cowboy/2.0/guide">User Guide</a></li>
-
-
- <li><a href="/docs/en/cowboy/2.0/manual">Function Reference</a></li>
-
-
-</ul>
-
-<h4 id="docs-nav">Navigation</h4>
-
-<h4>Version select</h4>
-<ul>
-
-
-
- <li><a href="/docs/en/cowboy/2.0/guide">2.0</a></li>
-
- <li><a href="/docs/en/cowboy/1.0/guide">1.0</a></li>
-
-</ul>
-
-</div>
-</div>
-</div>
-</div>
-
- <footer>
- <div class="container">
- <div class="row">
- <div class="span6">
- <p id="scroll-top"><a href="#">↑ Scroll to top</a></p>
- <nav>
- <ul>
- <li><a href="mailto:[email protected]" title="Contact us">Contact us</a></li><li><a href="https://github.com/ninenines/ninenines.github.io" title="Github repository">Contribute to this site</a></li>
- </ul>
- </nav>
- </div>
- <div class="span6 credits">
- <p><img src="/img/footer_logo.png"></p>
- <p>Copyright &copy; Loïc Hoguin 2012-2016</p>
- </div>
- </div>
- </div>
- </footer>
-
-
- <script src="/js/custom.js"></script>
- </body>
-</html>
-
-
diff --git a/docs/en/cowboy/2.0/guide/broken_clients.asciidoc b/docs/en/cowboy/2.0/guide/broken_clients.asciidoc
deleted file mode 100644
index 1d1a51a9..00000000
--- a/docs/en/cowboy/2.0/guide/broken_clients.asciidoc
+++ /dev/null
@@ -1,62 +0,0 @@
-[[broken_clients]]
-== Dealing with broken clients
-
-There exists a very large number of implementations for the
-HTTP protocol. Most widely used clients, like browsers,
-follow the standard quite well, but others may not. In
-particular custom enterprise clients tend to be very badly
-written.
-
-Cowboy tries to follow the standard as much as possible,
-but is not trying to handle every possible special cases.
-Instead Cowboy focuses on the cases reported in the wild,
-on the public Web.
-
-That means clients that ignore the HTTP standard completely
-may fail to understand Cowboy's responses. There are of
-course workarounds. This chapter aims to cover them.
-
-=== Lowercase headers
-
-Cowboy converts all headers it receives to lowercase, and
-similarly sends back headers all in lowercase. Some broken
-HTTP clients have issues with that.
-
-A simple way to solve this is to create an `onresponse` hook
-that will format the header names with the expected case.
-
-[source,erlang]
-----
-capitalize_hook(Status, Headers, Body, Req) ->
- Headers2 = [{cowboy_bstr:capitalize_token(N), V}
- || {N, V} <- Headers],
- cowboy_req:reply(Status, Headers2, Body, Req).
-----
-
-Note that HTTP/2 clients do not have that particular issue
-because the specification explicitly says all headers are
-lowercase, unlike HTTP which allows any case but treats
-them as case insensitive.
-
-=== Camel-case headers
-
-Sometimes it is desirable to keep the actual case used by
-clients, for example when acting as a proxy between two broken
-implementations. There is no easy solution for this other than
-forking the project and editing the `cowboy_protocol` file
-directly.
-
-// @todo This currently has no equivalent in Cowboy 2.0.
-// === Chunked transfer-encoding
-//
-// Sometimes an HTTP client advertises itself as HTTP/1.1 but
-// does not support chunked transfer-encoding. This is invalid
-// behavior, as HTTP/1.1 clients are required to support it.
-//
-// A simple workaround exists in these cases. By changing the
-// Req object response state to `waiting_stream`, Cowboy will
-// understand that it must use the identity transfer-encoding
-// when replying, just like if it was an HTTP/1.0 client.
-//
-// [source,erlang]
-// Req2 = cowboy_req:set(resp_state, waiting_stream).
diff --git a/docs/en/cowboy/2.0/guide/broken_clients/index.html b/docs/en/cowboy/2.0/guide/broken_clients/index.html
deleted file mode 100644
index 41e8d59f..00000000
--- a/docs/en/cowboy/2.0/guide/broken_clients/index.html
+++ /dev/null
@@ -1,203 +0,0 @@
-<!DOCTYPE html>
-<html lang="en">
-
-<head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <meta name="description" content="">
- <meta name="author" content="Loïc Hoguin based on a design from (Soft10) Pol Cámara">
-
- <meta name="generator" content="Hugo 0.17" />
-
- <title>Nine Nines: Dealing with broken clients</title>
-
- <link href='https://fonts.googleapis.com/css?family=Open+Sans:400,700,400italic' rel='stylesheet' type='text/css'>
- <link href="/css/99s.css?r=1" rel="stylesheet">
-
- <link rel="shortcut icon" href="/img/ico/favicon.ico">
- <link rel="apple-touch-icon-precomposed" sizes="114x114" href="/img/ico/apple-touch-icon-114.png">
- <link rel="apple-touch-icon-precomposed" sizes="72x72" href="/img/ico/apple-touch-icon-72.png">
- <link rel="apple-touch-icon-precomposed" href="/img/ico/apple-touch-icon-57.png">
-
-
-</head>
-
-
-<body class="">
- <header id="page-head">
- <div id="topbar" class="container">
- <div class="row">
- <div class="span2">
- <h1 id="logo"><a href="/" title="99s">99s</a></h1>
- </div>
- <div class="span10">
-
- <div id="side-header">
- <nav>
- <ul>
- <li><a title="Hear my thoughts" href="/articles">Articles</a></li>
- <li><a title="Watch my talks" href="/talks">Talks</a></li>
- <li class="active"><a title="Read the docs" href="/docs">Documentation</a></li>
- <li><a title="Request my services" href="/services">Consulting & Training</a></li>
- </ul>
- </nav>
- <ul id="social">
- <li>
- <a href="https://github.com/ninenines" title="Check my Github repositories"><img src="/img/ico_github.png" data-hover="/img/ico_github_alt.png" alt="Github"></a>
- </li>
- <li>
- <a title="Keep in touch!" href="http://twitter.com/lhoguin"><img src="/img/ico_microblog.png" data-hover="/img/ico_microblog_alt.png"></a>
- </li>
- <li>
- <a title="Contact me" href="mailto:[email protected]"><img src="/img/ico_mail.png" data-hover="/img/ico_mail_alt.png"></a>
- </li>
- </ul>
- </div>
- </div>
- </div>
- </div>
-
-
-</header>
-
-<div id="contents" class="two_col">
-<div class="container">
-<div class="row">
-<div id="docs" class="span9 maincol">
-
-<h1 class="lined-header"><span>Dealing with broken clients</span></h1>
-
-<div class="paragraph"><p>There exists a very large number of implementations for the
-HTTP protocol. Most widely used clients, like browsers,
-follow the standard quite well, but others may not. In
-particular custom enterprise clients tend to be very badly
-written.</p></div>
-<div class="paragraph"><p>Cowboy tries to follow the standard as much as possible,
-but is not trying to handle every possible special cases.
-Instead Cowboy focuses on the cases reported in the wild,
-on the public Web.</p></div>
-<div class="paragraph"><p>That means clients that ignore the HTTP standard completely
-may fail to understand Cowboy&#8217;s responses. There are of
-course workarounds. This chapter aims to cover them.</p></div>
-<div class="sect1">
-<h2 id="_lowercase_headers">Lowercase headers</h2>
-<div class="sectionbody">
-<div class="paragraph"><p>Cowboy converts all headers it receives to lowercase, and
-similarly sends back headers all in lowercase. Some broken
-HTTP clients have issues with that.</p></div>
-<div class="paragraph"><p>A simple way to solve this is to create an <code>onresponse</code> hook
-that will format the header names with the expected case.</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">capitalize_hook</span></span>(<span style="color: #009900">Status</span>, <span style="color: #009900">Headers</span>, <span style="color: #009900">Body</span>, <span style="color: #009900">Req</span>) <span style="color: #990000">-&gt;</span>
- <span style="color: #009900">Headers2</span> <span style="color: #990000">=</span> [{<span style="font-weight: bold"><span style="color: #000000">cowboy_bstr:capitalize_token</span></span>(<span style="color: #009900">N</span>), <span style="color: #009900">V</span>}
- || {<span style="color: #009900">N</span>, <span style="color: #009900">V</span>} <span style="color: #990000">&lt;-</span> <span style="color: #009900">Headers</span>],
- <span style="font-weight: bold"><span style="color: #000000">cowboy_req:reply</span></span>(<span style="color: #009900">Status</span>, <span style="color: #009900">Headers2</span>, <span style="color: #009900">Body</span>, <span style="color: #009900">Req</span>)<span style="color: #990000">.</span></tt></pre></div></div>
-<div class="paragraph"><p>Note that HTTP/2 clients do not have that particular issue
-because the specification explicitly says all headers are
-lowercase, unlike HTTP which allows any case but treats
-them as case insensitive.</p></div>
-</div>
-</div>
-<div class="sect1">
-<h2 id="_camel_case_headers">Camel-case headers</h2>
-<div class="sectionbody">
-<div class="paragraph"><p>Sometimes it is desirable to keep the actual case used by
-clients, for example when acting as a proxy between two broken
-implementations. There is no easy solution for this other than
-forking the project and editing the <code>cowboy_protocol</code> file
-directly.</p></div>
-</div>
-</div>
-
-
-
-
-
-
-
- <nav style="margin:1em 0">
-
- <a style="float:left" href="https://ninenines.eu/docs/en/cowboy/2.0/guide/architecture/">
- Architecture
- </a>
-
-
-
- <a style="float:right" href="https://ninenines.eu/docs/en/cowboy/2.0/guide/hooks/">
- Hooks
- </a>
-
- </nav>
-
-
-
-
-</div>
-
-<div class="span3 sidecol">
-
-
-<h3>
- Cowboy
- 2.0
-
- User Guide
-</h3>
-
-<ul>
-
- <li><a href="/docs/en/cowboy/2.0/guide">User Guide</a></li>
-
-
- <li><a href="/docs/en/cowboy/2.0/manual">Function Reference</a></li>
-
-
-</ul>
-
-<h4 id="docs-nav">Navigation</h4>
-
-<h4>Version select</h4>
-<ul>
-
-
-
- <li><a href="/docs/en/cowboy/2.0/guide">2.0</a></li>
-
- <li><a href="/docs/en/cowboy/1.0/guide">1.0</a></li>
-
-</ul>
-
-</div>
-</div>
-</div>
-</div>
-
- <footer>
- <div class="container">
- <div class="row">
- <div class="span6">
- <p id="scroll-top"><a href="#">↑ Scroll to top</a></p>
- <nav>
- <ul>
- <li><a href="mailto:[email protected]" title="Contact us">Contact us</a></li><li><a href="https://github.com/ninenines/ninenines.github.io" title="Github repository">Contribute to this site</a></li>
- </ul>
- </nav>
- </div>
- <div class="span6 credits">
- <p><img src="/img/footer_logo.png"></p>
- <p>Copyright &copy; Loïc Hoguin 2012-2016</p>
- </div>
- </div>
- </div>
- </footer>
-
-
- <script src="/js/custom.js"></script>
- </body>
-</html>
-
-
diff --git a/docs/en/cowboy/2.0/guide/constraints.asciidoc b/docs/en/cowboy/2.0/guide/constraints.asciidoc
index 7721831e..6cc10752 100644
--- a/docs/en/cowboy/2.0/guide/constraints.asciidoc
+++ b/docs/en/cowboy/2.0/guide/constraints.asciidoc
@@ -5,7 +5,7 @@ Constraints are validation and conversion functions applied
to user input.
They are used in various places in Cowboy, including the
-router and the request match functions.
+router and the `cowboy_req` match functions.
=== Syntax
@@ -36,10 +36,18 @@ check that the integer is positive:
[source,erlang]
----
-PositiveFun = fun(V) when V > 0 -> true; (_) -> false end,
+PositiveFun = fun
+ (_, V) when V > 0 ->
+ {ok, V};
+ (_, _) ->
+ {error, not_positive}
+end,
{my_value, [int, PositiveFun]}.
----
+We ignore the first fun argument in this snippet. We shouldn't.
+We will simply learn what it is later in this chapter.
+
When there's only one constraint, it can be provided directly
without wrapping it into a list:
@@ -62,30 +70,54 @@ Built-in constraints are specified as an atom:
=== Custom constraints
Custom constraints are specified as a fun. This fun takes
-a single argument and must return one of `true`, `{true, NewValue}`
-or `false`.
+two arguments. The first argument indicates the operation
+to be performed, and the second is the value. What the
+value is and what must be returned depends on the operation.
-`true` indicates the input is valid, `false` otherwise.
-The `{true, NewValue}` tuple is returned when the input
-is valid and the value has been converted. For example,
-the following constraint will convert the binary input
-to an integer:
+Cowboy currently defines three operations. The operation
+used for validating and converting user input is the `forward`
+operation.
[source,erlang]
----
-fun (Value0) when is_binary(Value0) ->
- try binary_to_integer(Value0) of
- Value -> {true, Value}
+int(forward, Value) ->
+ try
+ {ok, binary_to_integer(Value)}
catch _:_ ->
- false
- end.
+ {error, not_an_integer}
+ end;
+----
+
+The value must be returned even if it is not converted
+by the constraint.
+
+The `reverse` operation does the opposite: it
+takes a converted value and changes it back to what the
+user input would have been.
+
+[source,erlang]
+----
+int(reverse, Value) ->
+ try
+ {ok, integer_to_binary(Value)}
+ catch _:_ ->
+ {error, not_an_integer}
+ end;
+----
+
+Finally, the `format_error` operation takes an error
+returned by any other operation and returns a formatted
+human-readable error message.
+
+[source,erlang]
+----
+int(format_error, {not_an_integer, Value}) ->
+ io_lib:format("The value ~p is not an integer.", [Value]).
----
-Constraint functions should only crash because the programmer
-made an error when chaining constraints incorrectly (for example
-if the constraints were `[int, int]`, and not because of input.
-If the input is invalid then `false` must be returned.
+Notice that for this case you get both the error and
+the value that was given to the constraint that produced
+this error.
-In our snippet, the `is_binary/1` guard will crash only
-because of a programmer error, and the try block is there
-to ensure that we do not crash when the input is invalid.
+Cowboy will not catch exceptions coming from constraint
+functions. They should be written to not emit any exceptions.
diff --git a/docs/en/cowboy/2.0/guide/constraints/index.html b/docs/en/cowboy/2.0/guide/constraints/index.html
index 04171ebb..110adf07 100644
--- a/docs/en/cowboy/2.0/guide/constraints/index.html
+++ b/docs/en/cowboy/2.0/guide/constraints/index.html
@@ -70,7 +70,7 @@
<div class="paragraph"><p>Constraints are validation and conversion functions applied
to user input.</p></div>
<div class="paragraph"><p>They are used in various places in Cowboy, including the
-router and the request match functions.</p></div>
+router and the <code>cowboy_req</code> match functions.</p></div>
<div class="sect1">
<h2 id="_syntax">Syntax</h2>
<div class="sectionbody">
@@ -98,8 +98,15 @@ check that the integer is positive:</p></div>
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
-<pre><tt><span style="color: #009900">PositiveFun</span> <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #0000FF">fun</span></span>(<span style="color: #009900">V</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">V</span> <span style="color: #990000">&gt;</span> <span style="color: #993399">0</span> <span style="color: #990000">-&gt;</span> <span style="color: #000080">true</span>; (<span style="color: #990000">_</span>) <span style="color: #990000">-&gt;</span> <span style="color: #000080">false</span> <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>,
+<pre><tt><span style="color: #009900">PositiveFun</span> <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #0000FF">fun</span></span>
+ (<span style="color: #990000">_</span>, <span style="color: #009900">V</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #009900">V</span> <span style="color: #990000">&gt;</span> <span style="color: #993399">0</span> <span style="color: #990000">-&gt;</span>
+ {<span style="color: #FF6600">ok</span>, <span style="color: #009900">V</span>};
+ (<span style="color: #990000">_</span>, <span style="color: #990000">_</span>) <span style="color: #990000">-&gt;</span>
+ {<span style="color: #FF6600">error</span>, <span style="color: #FF6600">not_positive</span>}
+<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>,
{<span style="color: #FF6600">my_value</span>, [<span style="color: #FF6600">int</span>, <span style="color: #009900">PositiveFun</span>]}<span style="color: #990000">.</span></tt></pre></div></div>
+<div class="paragraph"><p>We ignore the first fun argument in this snippet. We shouldn&#8217;t.
+We will simply learn what it is later in this chapter.</p></div>
<div class="paragraph"><p>When there&#8217;s only one constraint, it can be provided directly
without wrapping it into a list:</p></div>
<div class="listingblock">
@@ -145,31 +152,54 @@ cellspacing="0" cellpadding="4">
<h2 id="_custom_constraints">Custom constraints</h2>
<div class="sectionbody">
<div class="paragraph"><p>Custom constraints are specified as a fun. This fun takes
-a single argument and must return one of <code>true</code>, <code>{true, NewValue}</code>
-or <code>false</code>.</p></div>
-<div class="paragraph"><p><code>true</code> indicates the input is valid, <code>false</code> otherwise.
-The <code>{true, NewValue}</code> tuple is returned when the input
-is valid and the value has been converted. For example,
-the following constraint will convert the binary input
-to an integer:</p></div>
+two arguments. The first argument indicates the operation
+to be performed, and the second is the value. What the
+value is and what must be returned depends on the operation.</p></div>
+<div class="paragraph"><p>Cowboy currently defines three operations. The operation
+used for validating and converting user input is the <code>forward</code>
+operation.</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: #0000FF">fun</span></span> (<span style="color: #009900">Value0</span>) <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="font-weight: bold"><span style="color: #000080">is_binary</span></span>(<span style="color: #009900">Value0</span>) <span style="color: #990000">-&gt;</span>
- <span style="font-weight: bold"><span style="color: #0000FF">try</span></span> <span style="font-weight: bold"><span style="color: #000000">binary_to_integer</span></span>(<span style="color: #009900">Value0</span>) <span style="font-weight: bold"><span style="color: #0000FF">of</span></span>
- <span style="color: #009900">Value</span> <span style="color: #990000">-&gt;</span> {<span style="color: #000080">true</span>, <span style="color: #009900">Value</span>}
+<pre><tt><span style="font-weight: bold"><span style="color: #000000">int</span></span>(<span style="color: #FF6600">forward</span>, <span style="color: #009900">Value</span>) <span style="color: #990000">-&gt;</span>
+ <span style="font-weight: bold"><span style="color: #0000FF">try</span></span>
+ {<span style="color: #FF6600">ok</span>, <span style="font-weight: bold"><span style="color: #000000">binary_to_integer</span></span>(<span style="color: #009900">Value</span>)}
<span style="font-weight: bold"><span style="color: #0000FF">catch</span></span> <span style="color: #990000">_:_</span> <span style="color: #990000">-&gt;</span>
- <span style="color: #000080">false</span>
- <span style="font-weight: bold"><span style="color: #0000FF">end</span></span><span style="color: #990000">.</span></tt></pre></div></div>
-<div class="paragraph"><p>Constraint functions should only crash because the programmer
-made an error when chaining constraints incorrectly (for example
-if the constraints were <code>[int, int]</code>, and not because of input.
-If the input is invalid then <code>false</code> must be returned.</p></div>
-<div class="paragraph"><p>In our snippet, the <code>is_binary/1</code> guard will crash only
-because of a programmer error, and the try block is there
-to ensure that we do not crash when the input is invalid.</p></div>
+ {<span style="color: #FF6600">error</span>, <span style="color: #FF6600">not_an_integer</span>}
+ <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>;</tt></pre></div></div>
+<div class="paragraph"><p>The value must be returned even if it is not converted
+by the constraint.</p></div>
+<div class="paragraph"><p>The <code>reverse</code> operation does the opposite: it
+takes a converted value and changes it back to what the
+user input would have been.</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">int</span></span>(<span style="color: #FF6600">reverse</span>, <span style="color: #009900">Value</span>) <span style="color: #990000">-&gt;</span>
+ <span style="font-weight: bold"><span style="color: #0000FF">try</span></span>
+ {<span style="color: #FF6600">ok</span>, <span style="font-weight: bold"><span style="color: #000000">integer_to_binary</span></span>(<span style="color: #009900">Value</span>)}
+ <span style="font-weight: bold"><span style="color: #0000FF">catch</span></span> <span style="color: #990000">_:_</span> <span style="color: #990000">-&gt;</span>
+ {<span style="color: #FF6600">error</span>, <span style="color: #FF6600">not_an_integer</span>}
+ <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>;</tt></pre></div></div>
+<div class="paragraph"><p>Finally, the <code>format_error</code> operation takes an error
+returned by any other operation and returns a formatted
+human-readable error message.</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">int</span></span>(<span style="color: #FF6600">format_error</span>, {<span style="color: #FF6600">not_an_integer</span>, <span style="color: #009900">Value</span>}) <span style="color: #990000">-&gt;</span>
+ <span style="font-weight: bold"><span style="color: #000000">io_lib:format</span></span>(<span style="color: #FF0000">"The value ~p is not an integer."</span>, [<span style="color: #009900">Value</span>])<span style="color: #990000">.</span></tt></pre></div></div>
+<div class="paragraph"><p>Notice that for this case you get both the error and
+the value that was given to the constraint that produced
+this error.</p></div>
+<div class="paragraph"><p>Cowboy will not catch exceptions coming from constraint
+functions. They should be written to not emit any exceptions.</p></div>
</div>
</div>
diff --git a/docs/en/cowboy/2.0/guide/flow_diagram.asciidoc b/docs/en/cowboy/2.0/guide/flow_diagram.asciidoc
index ad2110dc..2d35d4d6 100644
--- a/docs/en/cowboy/2.0/guide/flow_diagram.asciidoc
+++ b/docs/en/cowboy/2.0/guide/flow_diagram.asciidoc
@@ -1,12 +1,109 @@
[[flow_diagram]]
== Flow diagram
-Placeholder chapter.
+Cowboy is a lightweight HTTP server with support for HTTP/1.1,
+HTTP/2 and Websocket.
-Cowboy 2.0 has changed the request flow and general architecture.
-You can read about the Cowboy 1.0 architecture and flow here:
+It is built on top of Ranch. Please see the Ranch guide for more
+information about how the network connections are handled.
-* xref:architecture[Architecture]
-* xref:overview[Overview]
+=== Overview
-This chapter will be updated in a future pre-release.
+image::http_req_resp.png[HTTP request/response flowchart]
+
+As you can see on the diagram, the client
+begins by connecting to the server. This step is handled
+by a Ranch acceptor, which is a process dedicated to
+accepting new connections.
+
+After Ranch accepts a new connection, whether it is an
+HTTP/1.1 or HTTP/2 connection, Cowboy starts receiving
+requests and handling them.
+
+In HTTP/1.1 all requests come sequentially. In HTTP/2
+the requests may arrive and be processed concurrently.
+
+When a request comes in, Cowboy creates a stream, which
+is a set of request/response and all the events associated
+with them. The protocol code in Cowboy defers the handling
+of these streams to stream handler modules. When you
+configure Cowboy you may define one or more module that
+will receive all events associated with a stream, including
+the request, response, bodies, Erlang messages and more.
+
+By default Cowboy comes configured with a stream handler
+called `cowboy_stream_h`. This stream handler will create
+a new process for every request coming in, and then
+communicate with this process to read the body or send
+a response back. The request process executes middlewares
+which, by default, including the router and then the
+execution of handlers. Like stream handlers, middlewares
+may also be customized.
+
+A response may be sent at almost any point in this
+diagram. If the response must be sent before the stream
+is initialized (because an error occurred early, for
+example) then stream handlers receive a special event
+indicating this error.
+
+=== Protocol-specific headers
+
+Cowboy takes care of protocol-specific headers and prevents
+you from sending them manually. For HTTP/1.1 this includes
+the `transfer-encoding` and `connection` headers. For HTTP/2
+this includes the colon headers like `:status`.
+
+Cowboy will also remove protocol-specific headers from
+requests before passing them to stream handlers. Cowboy
+tries to hide the implementation details of all protocols
+as well as possible.
+
+=== Number of processes per connection
+
+By default, Cowboy will use one process per connection,
+plus one process per set of request/response (called a
+stream, internally).
+
+The reason it creates a new process for every request is due
+to the requirements of HTTP/2 where requests are executed
+concurrently and independently from the connection. The
+frames from the different requests end up interleaved on
+the single TCP connection.
+
+The request processes are never reused. There is therefore
+no need to perform any cleanup after the response has been
+sent. The process will terminate and Erlang/OTP will reclaim
+all memory at once.
+
+Cowboy ultimately does not require more than one process
+per connection. It is possible to interact with the connection
+directly from a stream handler, a low level interface to Cowboy.
+They are executed from within the connection process, and can
+handle the incoming requests and send responses. This is however
+not recommended in normal circumstances, as a stream handler
+taking too long to execute could have a negative impact on
+concurrent requests or the state of the connection itself.
+
+=== Date header
+
+Because querying for the current date and time can be expensive,
+Cowboy generates one 'Date' header value every second, shares it
+to all other processes, which then simply copy it in the response.
+This allows compliance with HTTP/1.1 with no actual performance loss.
+
+=== Binaries
+
+Cowboy makes extensive use of binaries.
+
+Binaries are more efficient than lists for representing
+strings because they take less memory space. Processing
+performance can vary depending on the operation. Binaries
+are known for generally getting a great boost if the code
+is compiled natively. Please see the HiPE documentation
+for more details.
+
+Binaries may end up being shared between processes. This
+can lead to some large memory usage when one process keeps
+the binary data around forever without freeing it. If you
+see some weird memory usage in your application, this might
+be the cause.
diff --git a/docs/en/cowboy/2.0/guide/flow_diagram/index.html b/docs/en/cowboy/2.0/guide/flow_diagram/index.html
index 976eb09d..72e78d28 100644
--- a/docs/en/cowboy/2.0/guide/flow_diagram/index.html
+++ b/docs/en/cowboy/2.0/guide/flow_diagram/index.html
@@ -67,22 +67,113 @@
<h1 class="lined-header"><span>Flow diagram</span></h1>
-<div class="paragraph"><p>Placeholder chapter.</p></div>
-<div class="paragraph"><p>Cowboy 2.0 has changed the request flow and general architecture.
-You can read about the Cowboy 1.0 architecture and flow here:</p></div>
-<div class="ulist"><ul>
-<li>
-<p>
-<a href="../architecture">Architecture</a>
-</p>
-</li>
-<li>
-<p>
-<a href="../overview">Overview</a>
-</p>
-</li>
-</ul></div>
-<div class="paragraph"><p>This chapter will be updated in a future pre-release.</p></div>
+<div class="paragraph"><p>Cowboy is a lightweight HTTP server with support for HTTP/1.1,
+HTTP/2 and Websocket.</p></div>
+<div class="paragraph"><p>It is built on top of Ranch. Please see the Ranch guide for more
+information about how the network connections are handled.</p></div>
+<div class="sect1">
+<h2 id="_overview">Overview</h2>
+<div class="sectionbody">
+<div class="imageblock">
+<div class="content">
+<img src="../http_req_resp.png" alt="HTTP request/response flowchart" />
+</div>
+</div>
+<div class="paragraph"><p>As you can see on the diagram, the client
+begins by connecting to the server. This step is handled
+by a Ranch acceptor, which is a process dedicated to
+accepting new connections.</p></div>
+<div class="paragraph"><p>After Ranch accepts a new connection, whether it is an
+HTTP/1.1 or HTTP/2 connection, Cowboy starts receiving
+requests and handling them.</p></div>
+<div class="paragraph"><p>In HTTP/1.1 all requests come sequentially. In HTTP/2
+the requests may arrive and be processed concurrently.</p></div>
+<div class="paragraph"><p>When a request comes in, Cowboy creates a stream, which
+is a set of request/response and all the events associated
+with them. The protocol code in Cowboy defers the handling
+of these streams to stream handler modules. When you
+configure Cowboy you may define one or more module that
+will receive all events associated with a stream, including
+the request, response, bodies, Erlang messages and more.</p></div>
+<div class="paragraph"><p>By default Cowboy comes configured with a stream handler
+called <code>cowboy_stream_h</code>. This stream handler will create
+a new process for every request coming in, and then
+communicate with this process to read the body or send
+a response back. The request process executes middlewares
+which, by default, including the router and then the
+execution of handlers. Like stream handlers, middlewares
+may also be customized.</p></div>
+<div class="paragraph"><p>A response may be sent at almost any point in this
+diagram. If the response must be sent before the stream
+is initialized (because an error occurred early, for
+example) then stream handlers receive a special event
+indicating this error.</p></div>
+</div>
+</div>
+<div class="sect1">
+<h2 id="_protocol_specific_headers">Protocol-specific headers</h2>
+<div class="sectionbody">
+<div class="paragraph"><p>Cowboy takes care of protocol-specific headers and prevents
+you from sending them manually. For HTTP/1.1 this includes
+the <code>transfer-encoding</code> and <code>connection</code> headers. For HTTP/2
+this includes the colon headers like <code>:status</code>.</p></div>
+<div class="paragraph"><p>Cowboy will also remove protocol-specific headers from
+requests before passing them to stream handlers. Cowboy
+tries to hide the implementation details of all protocols
+as well as possible.</p></div>
+</div>
+</div>
+<div class="sect1">
+<h2 id="_number_of_processes_per_connection">Number of processes per connection</h2>
+<div class="sectionbody">
+<div class="paragraph"><p>By default, Cowboy will use one process per connection,
+plus one process per set of request/response (called a
+stream, internally).</p></div>
+<div class="paragraph"><p>The reason it creates a new process for every request is due
+to the requirements of HTTP/2 where requests are executed
+concurrently and independently from the connection. The
+frames from the different requests end up interleaved on
+the single TCP connection.</p></div>
+<div class="paragraph"><p>The request processes are never reused. There is therefore
+no need to perform any cleanup after the response has been
+sent. The process will terminate and Erlang/OTP will reclaim
+all memory at once.</p></div>
+<div class="paragraph"><p>Cowboy ultimately does not require more than one process
+per connection. It is possible to interact with the connection
+directly from a stream handler, a low level interface to Cowboy.
+They are executed from within the connection process, and can
+handle the incoming requests and send responses. This is however
+not recommended in normal circumstances, as a stream handler
+taking too long to execute could have a negative impact on
+concurrent requests or the state of the connection itself.</p></div>
+</div>
+</div>
+<div class="sect1">
+<h2 id="_date_header">Date header</h2>
+<div class="sectionbody">
+<div class="paragraph"><p>Because querying for the current date and time can be expensive,
+Cowboy generates one <em>Date</em> header value every second, shares it
+to all other processes, which then simply copy it in the response.
+This allows compliance with HTTP/1.1 with no actual performance loss.</p></div>
+</div>
+</div>
+<div class="sect1">
+<h2 id="_binaries">Binaries</h2>
+<div class="sectionbody">
+<div class="paragraph"><p>Cowboy makes extensive use of binaries.</p></div>
+<div class="paragraph"><p>Binaries are more efficient than lists for representing
+strings because they take less memory space. Processing
+performance can vary depending on the operation. Binaries
+are known for generally getting a great boost if the code
+is compiled natively. Please see the HiPE documentation
+for more details.</p></div>
+<div class="paragraph"><p>Binaries may end up being shared between processes. This
+can lead to some large memory usage when one process keeps
+the binary data around forever without freeing it. If you
+see some weird memory usage in your application, this might
+be the cause.</p></div>
+</div>
+</div>
diff --git a/docs/en/cowboy/2.0/guide/handlers.asciidoc b/docs/en/cowboy/2.0/guide/handlers.asciidoc
index e073dfb6..fe6f4623 100644
--- a/docs/en/cowboy/2.0/guide/handlers.asciidoc
+++ b/docs/en/cowboy/2.0/guide/handlers.asciidoc
@@ -68,17 +68,6 @@ init(Req, State) ->
{cowboy_websocket, Req, State}.
----
-You can also switch to your own custom handler type:
-
-[source,erlang]
-----
-init(Req, State) ->
- {my_handler_type, Req, State}.
-----
-
-How to implement a custom handler type is described in the
-xref:sub_protocols[Sub protocols] chapter.
-
=== Cleaning up
All handler types provide the optional `terminate/3` callback.
diff --git a/docs/en/cowboy/2.0/guide/handlers/index.html b/docs/en/cowboy/2.0/guide/handlers/index.html
index ba92d89c..dbb50c85 100644
--- a/docs/en/cowboy/2.0/guide/handlers/index.html
+++ b/docs/en/cowboy/2.0/guide/handlers/index.html
@@ -129,16 +129,6 @@ http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-weight: bold"><span style="color: #000000">init</span></span>(<span style="color: #009900">Req</span>, <span style="color: #009900">State</span>) <span style="color: #990000">-&gt;</span>
{<span style="color: #FF6600">cowboy_websocket</span>, <span style="color: #009900">Req</span>, <span style="color: #009900">State</span>}<span style="color: #990000">.</span></tt></pre></div></div>
-<div class="paragraph"><p>You can also switch to your own custom handler type:</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">init</span></span>(<span style="color: #009900">Req</span>, <span style="color: #009900">State</span>) <span style="color: #990000">-&gt;</span>
- {<span style="color: #FF6600">my_handler_type</span>, <span style="color: #009900">Req</span>, <span style="color: #009900">State</span>}<span style="color: #990000">.</span></tt></pre></div></div>
-<div class="paragraph"><p>How to implement a custom handler type is described in the
-<a href="../sub_protocols">Sub protocols</a> chapter.</p></div>
</div>
</div>
<div class="sect1">
diff --git a/docs/en/cowboy/2.0/guide/hooks.asciidoc b/docs/en/cowboy/2.0/guide/hooks.asciidoc
deleted file mode 100644
index fc79f8ac..00000000
--- a/docs/en/cowboy/2.0/guide/hooks.asciidoc
+++ /dev/null
@@ -1,46 +0,0 @@
-[[hooks]]
-== Hooks
-
-Hooks allow the user to customize Cowboy's behavior during specific
-operations.
-
-=== Onresponse
-
-The `onresponse` hook is called right before sending the response
-to the socket. It can be used for the purposes of logging responses,
-or for modifying the response headers or body. The best example is
-providing custom error pages.
-
-Note that this function MUST NOT crash. Cowboy may or may not send a
-reply if this function crashes. If a reply is sent, the hook MUST
-explicitly provide all headers that are needed.
-
-You can specify the `onresponse` hook when creating the listener.
-
-[source,erlang]
-----
-cowboy:start_http(my_http_listener, 100,
- [{port, 8080}],
- [
- {env, [{dispatch, Dispatch}]},
- {onresponse, fun ?MODULE:custom_404_hook/4}
- ]
-).
-----
-
-The following hook function will provide a custom body for 404 errors
-when it has not been provided before, and will let Cowboy proceed with
-the default response otherwise.
-
-[source,erlang]
-----
-custom_404_hook(404, Headers, <<>>, Req) ->
- Body = <<"404 Not Found.">>,
- Headers2 = lists:keyreplace(<<"content-length">>, 1, Headers,
- {<<"content-length">>, integer_to_list(byte_size(Body))}),
- cowboy_req:reply(404, Headers2, Body, Req);
-custom_404_hook(_, _, _, Req) ->
- Req.
-----
-
-Again, make sure to always return the last request object obtained.
diff --git a/docs/en/cowboy/2.0/guide/hooks/index.html b/docs/en/cowboy/2.0/guide/hooks/index.html
deleted file mode 100644
index dd42215e..00000000
--- a/docs/en/cowboy/2.0/guide/hooks/index.html
+++ /dev/null
@@ -1,201 +0,0 @@
-<!DOCTYPE html>
-<html lang="en">
-
-<head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <meta name="description" content="">
- <meta name="author" content="Loïc Hoguin based on a design from (Soft10) Pol Cámara">
-
- <meta name="generator" content="Hugo 0.17" />
-
- <title>Nine Nines: Hooks</title>
-
- <link href='https://fonts.googleapis.com/css?family=Open+Sans:400,700,400italic' rel='stylesheet' type='text/css'>
- <link href="/css/99s.css?r=1" rel="stylesheet">
-
- <link rel="shortcut icon" href="/img/ico/favicon.ico">
- <link rel="apple-touch-icon-precomposed" sizes="114x114" href="/img/ico/apple-touch-icon-114.png">
- <link rel="apple-touch-icon-precomposed" sizes="72x72" href="/img/ico/apple-touch-icon-72.png">
- <link rel="apple-touch-icon-precomposed" href="/img/ico/apple-touch-icon-57.png">
-
-
-</head>
-
-
-<body class="">
- <header id="page-head">
- <div id="topbar" class="container">
- <div class="row">
- <div class="span2">
- <h1 id="logo"><a href="/" title="99s">99s</a></h1>
- </div>
- <div class="span10">
-
- <div id="side-header">
- <nav>
- <ul>
- <li><a title="Hear my thoughts" href="/articles">Articles</a></li>
- <li><a title="Watch my talks" href="/talks">Talks</a></li>
- <li class="active"><a title="Read the docs" href="/docs">Documentation</a></li>
- <li><a title="Request my services" href="/services">Consulting & Training</a></li>
- </ul>
- </nav>
- <ul id="social">
- <li>
- <a href="https://github.com/ninenines" title="Check my Github repositories"><img src="/img/ico_github.png" data-hover="/img/ico_github_alt.png" alt="Github"></a>
- </li>
- <li>
- <a title="Keep in touch!" href="http://twitter.com/lhoguin"><img src="/img/ico_microblog.png" data-hover="/img/ico_microblog_alt.png"></a>
- </li>
- <li>
- <a title="Contact me" href="mailto:[email protected]"><img src="/img/ico_mail.png" data-hover="/img/ico_mail_alt.png"></a>
- </li>
- </ul>
- </div>
- </div>
- </div>
- </div>
-
-
-</header>
-
-<div id="contents" class="two_col">
-<div class="container">
-<div class="row">
-<div id="docs" class="span9 maincol">
-
-<h1 class="lined-header"><span>Hooks</span></h1>
-
-<div class="paragraph"><p>Hooks allow the user to customize Cowboy&#8217;s behavior during specific
-operations.</p></div>
-<div class="sect1">
-<h2 id="_onresponse">Onresponse</h2>
-<div class="sectionbody">
-<div class="paragraph"><p>The <code>onresponse</code> hook is called right before sending the response
-to the socket. It can be used for the purposes of logging responses,
-or for modifying the response headers or body. The best example is
-providing custom error pages.</p></div>
-<div class="paragraph"><p>Note that this function MUST NOT crash. Cowboy may or may not send a
-reply if this function crashes. If a reply is sent, the hook MUST
-explicitly provide all headers that are needed.</p></div>
-<div class="paragraph"><p>You can specify the <code>onresponse</code> hook when creating the 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">onresponse</span>, <span style="font-weight: bold"><span style="color: #0000FF">fun</span></span> <span style="font-weight: bold"><span style="color: #000080">?MODULE</span></span><span style="color: #990000">:</span><span style="font-weight: bold"><span style="color: #000000">custom_404_hook</span></span><span style="color: #990000">/</span><span style="color: #993399">4</span>}
- ]
-)<span style="color: #990000">.</span></tt></pre></div></div>
-<div class="paragraph"><p>The following hook function will provide a custom body for 404 errors
-when it has not been provided before, and will let Cowboy proceed with
-the default response otherwise.</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">custom_404_hook</span></span>(<span style="color: #993399">404</span>, <span style="color: #009900">Headers</span>, <span style="color: #990000">&lt;&lt;&gt;&gt;</span>, <span style="color: #009900">Req</span>) <span style="color: #990000">-&gt;</span>
- <span style="color: #009900">Body</span> <span style="color: #990000">=</span> <span style="color: #990000">&lt;&lt;</span><span style="color: #FF0000">"404 Not Found."</span><span style="color: #990000">&gt;&gt;</span>,
- <span style="color: #009900">Headers2</span> <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">lists:keyreplace</span></span>(<span style="color: #990000">&lt;&lt;</span><span style="color: #FF0000">"content-length"</span><span style="color: #990000">&gt;&gt;</span>, <span style="color: #993399">1</span>, <span style="color: #009900">Headers</span>,
- {<span style="color: #990000">&lt;&lt;</span><span style="color: #FF0000">"content-length"</span><span style="color: #990000">&gt;&gt;</span>, <span style="font-weight: bold"><span style="color: #000080">integer_to_list</span></span>(<span style="font-weight: bold"><span style="color: #000080">byte_size</span></span>(<span style="color: #009900">Body</span>))}),
- <span style="font-weight: bold"><span style="color: #000000">cowboy_req:reply</span></span>(<span style="color: #993399">404</span>, <span style="color: #009900">Headers2</span>, <span style="color: #009900">Body</span>, <span style="color: #009900">Req</span>);
-<span style="font-weight: bold"><span style="color: #000000">custom_404_hook</span></span>(<span style="color: #990000">_</span>, <span style="color: #990000">_</span>, <span style="color: #990000">_</span>, <span style="color: #009900">Req</span>) <span style="color: #990000">-&gt;</span>
- <span style="color: #009900">Req</span><span style="color: #990000">.</span></tt></pre></div></div>
-<div class="paragraph"><p>Again, make sure to always return the last request object obtained.</p></div>
-</div>
-</div>
-
-
-
-
-
-
-
- <nav style="margin:1em 0">
-
- <a style="float:left" href="https://ninenines.eu/docs/en/cowboy/2.0/guide/broken_clients/">
- Dealing with broken clients
- </a>
-
-
-
- <a style="float:right" href="https://ninenines.eu/docs/en/cowboy/2.0/guide/overview/">
- Request overview
- </a>
-
- </nav>
-
-
-
-
-</div>
-
-<div class="span3 sidecol">
-
-
-<h3>
- Cowboy
- 2.0
-
- User Guide
-</h3>
-
-<ul>
-
- <li><a href="/docs/en/cowboy/2.0/guide">User Guide</a></li>
-
-
- <li><a href="/docs/en/cowboy/2.0/manual">Function Reference</a></li>
-
-
-</ul>
-
-<h4 id="docs-nav">Navigation</h4>
-
-<h4>Version select</h4>
-<ul>
-
-
-
- <li><a href="/docs/en/cowboy/2.0/guide">2.0</a></li>
-
- <li><a href="/docs/en/cowboy/1.0/guide">1.0</a></li>
-
-</ul>
-
-</div>
-</div>
-</div>
-</div>
-
- <footer>
- <div class="container">
- <div class="row">
- <div class="span6">
- <p id="scroll-top"><a href="#">↑ Scroll to top</a></p>
- <nav>
- <ul>
- <li><a href="mailto:[email protected]" title="Contact us">Contact us</a></li><li><a href="https://github.com/ninenines/ninenines.github.io" title="Github repository">Contribute to this site</a></li>
- </ul>
- </nav>
- </div>
- <div class="span6 credits">
- <p><img src="/img/footer_logo.png"></p>
- <p>Copyright &copy; Loïc Hoguin 2012-2016</p>
- </div>
- </div>
- </div>
- </footer>
-
-
- <script src="/js/custom.js"></script>
- </body>
-</html>
-
-
diff --git a/docs/en/cowboy/2.0/guide/http_req_resp.png b/docs/en/cowboy/2.0/guide/http_req_resp.png
index 8c9cae99..41c17c8a 100644
--- a/docs/en/cowboy/2.0/guide/http_req_resp.png
+++ b/docs/en/cowboy/2.0/guide/http_req_resp.png
Binary files differ
diff --git a/docs/en/cowboy/2.0/guide/http_req_resp.svg b/docs/en/cowboy/2.0/guide/http_req_resp.svg
index d1e7f784..acedb152 100644
--- a/docs/en/cowboy/2.0/guide/http_req_resp.svg
+++ b/docs/en/cowboy/2.0/guide/http_req_resp.svg
@@ -15,7 +15,7 @@
height="1052.3622047"
id="svg2"
version="1.1"
- inkscape:version="0.48.4 r9939"
+ inkscape:version="0.92.1 r"
sodipodi:docname="http_req_resp.svg"
inkscape:export-filename="/home/essen/Dropbox/Public/drawing.png"
inkscape:export-xdpi="90"
@@ -65,15 +65,15 @@
inkscape:pageopacity="1"
inkscape:pageshadow="2"
inkscape:zoom="1.4142136"
- inkscape:cx="82.28271"
- inkscape:cy="764.83183"
+ inkscape:cx="172.08527"
+ inkscape:cy="762.31079"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="false"
- inkscape:window-width="2560"
- inkscape:window-height="1402"
+ inkscape:window-width="1920"
+ inkscape:window-height="1043"
inkscape:window-x="0"
- inkscape:window-y="38"
+ inkscape:window-y="0"
inkscape:window-maximized="1"
inkscape:snap-global="true"
showguides="true">
@@ -101,51 +101,117 @@
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1">
- <path
- inkscape:export-ydpi="89.926643"
- inkscape:export-xdpi="89.926643"
- inkscape:export-filename="/home/essen/extend/cowboy/guide/http_req_resp.png"
- inkscape:connector-curvature="0"
- id="use5779"
- d="M 194.29441,340.67017 369.64493,238.3853"
- style="fill:none;stroke:#6d8e41;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:2, 4;stroke-dashoffset:0" />
- <path
- inkscape:export-ydpi="89.926643"
- inkscape:export-xdpi="89.926643"
- inkscape:export-filename="/home/essen/extend/cowboy/guide/http_req_resp.png"
- inkscape:connector-curvature="0"
- id="use5777"
- d="m 178.49877,231.1517 203.00246,0.045"
- style="fill:none;stroke:#6d8e41;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:1.99999999, 3.99999998;stroke-dashoffset:0" />
- <use
- x="0"
- y="0"
- xlink:href="#g5650"
- id="use5753"
- transform="translate(475.11201,-117.70525)"
- width="744.09448"
- height="1052.3622"
- inkscape:export-filename="/home/essen/extend/cowboy/guide/http_req_resp.png"
- inkscape:export-xdpi="89.926643"
- inkscape:export-ydpi="89.926643" />
- <use
- x="0"
- y="0"
- xlink:href="#use5753"
- id="use5755"
- transform="translate(3.984568e-6,86.977569)"
- width="744.09448"
- height="1052.3622"
- inkscape:export-filename="/home/essen/extend/cowboy/guide/http_req_resp.png"
- inkscape:export-xdpi="89.926643"
- inkscape:export-ydpi="89.926643" />
+ <g
+ transform="translate(193.54707,-32.134105)"
+ id="g5650-5-0">
+ <path
+ inkscape:connector-curvature="0"
+ id="path5570-3-9"
+ d="m -57.78256,351.41962 v 52.3259"
+ style="opacity:0.8;fill:none;stroke:#6d8e41;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+ <path
+ transform="matrix(0.58787746,0,0,0.58787746,73.160466,163.35774)"
+ inkscape:transform-center-y="2.1823437"
+ d="m -222.73865,430.10821 -12.85982,-22.27386 25.71964,0 z"
+ inkscape:randomized="0"
+ inkscape:rounded="0"
+ inkscape:flatsided="true"
+ sodipodi:arg2="2.6179939"
+ sodipodi:arg1="1.5707963"
+ sodipodi:r2="7.4246211"
+ sodipodi:r1="14.849242"
+ sodipodi:cy="415.25897"
+ sodipodi:cx="-222.73865"
+ sodipodi:sides="3"
+ id="path5576-5-3"
+ style="opacity:0.8;fill:#6d8e41;fill-opacity:1;fill-rule:nonzero;stroke:#6d8e41;stroke-width:0;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
+ sodipodi:type="star" />
+ </g>
+ <g
+ transform="rotate(180,50.658226,375.46461)"
+ id="g5650-6-6">
+ <path
+ inkscape:connector-curvature="0"
+ id="path5570-2-0"
+ d="m -57.78256,351.41962 v 52.3259"
+ style="opacity:0.8;fill:none;stroke:#6d8e41;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+ <path
+ transform="matrix(0.58787746,0,0,0.58787746,73.160466,163.35774)"
+ inkscape:transform-center-y="2.1823437"
+ d="m -222.73865,430.10821 -12.85982,-22.27386 25.71964,0 z"
+ inkscape:randomized="0"
+ inkscape:rounded="0"
+ inkscape:flatsided="true"
+ sodipodi:arg2="2.6179939"
+ sodipodi:arg1="1.5707963"
+ sodipodi:r2="7.4246211"
+ sodipodi:r1="14.849242"
+ sodipodi:cy="415.25897"
+ sodipodi:cx="-222.73865"
+ sodipodi:sides="3"
+ id="path5576-9-6"
+ style="opacity:0.8;fill:#6d8e41;fill-opacity:1;fill-rule:nonzero;stroke:#6d8e41;stroke-width:0;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
+ sodipodi:type="star" />
+ </g>
+ <g
+ transform="translate(193.54707,-119.75468)"
+ id="g5650-5">
+ <path
+ inkscape:connector-curvature="0"
+ id="path5570-3"
+ d="m -57.78256,351.41962 v 52.3259"
+ style="opacity:0.8;fill:none;stroke:#6d8e41;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+ <path
+ transform="matrix(0.58787746,0,0,0.58787746,73.160466,163.35774)"
+ inkscape:transform-center-y="2.1823437"
+ d="m -222.73865,430.10821 -12.85982,-22.27386 25.71964,0 z"
+ inkscape:randomized="0"
+ inkscape:rounded="0"
+ inkscape:flatsided="true"
+ sodipodi:arg2="2.6179939"
+ sodipodi:arg1="1.5707963"
+ sodipodi:r2="7.4246211"
+ sodipodi:r1="14.849242"
+ sodipodi:cy="415.25897"
+ sodipodi:cx="-222.73865"
+ sodipodi:sides="3"
+ id="path5576-5"
+ style="opacity:0.8;fill:#6d8e41;fill-opacity:1;fill-rule:nonzero;stroke:#6d8e41;stroke-width:0;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
+ sodipodi:type="star" />
+ </g>
+ <g
+ transform="rotate(180,50.658226,331.65432)"
+ id="g5650-6">
+ <path
+ inkscape:connector-curvature="0"
+ id="path5570-2"
+ d="m -57.78256,351.41962 v 52.3259"
+ style="opacity:0.8;fill:none;stroke:#6d8e41;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
+ <path
+ transform="matrix(0.58787746,0,0,0.58787746,73.160466,163.35774)"
+ inkscape:transform-center-y="2.1823437"
+ d="m -222.73865,430.10821 -12.85982,-22.27386 25.71964,0 z"
+ inkscape:randomized="0"
+ inkscape:rounded="0"
+ inkscape:flatsided="true"
+ sodipodi:arg2="2.6179939"
+ sodipodi:arg1="1.5707963"
+ sodipodi:r2="7.4246211"
+ sodipodi:r1="14.849242"
+ sodipodi:cy="415.25897"
+ sodipodi:cx="-222.73865"
+ sodipodi:sides="3"
+ id="path5576-9"
+ style="opacity:0.8;fill:#6d8e41;fill-opacity:1;fill-rule:nonzero;stroke:#6d8e41;stroke-width:0;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
+ sodipodi:type="star" />
+ </g>
<rect
- style="fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:#a9ca7d;stroke-width:2.44279909;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0"
+ style="fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:#a9ca7d;stroke-width:2.44279909;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
id="rect5367"
width="207.05719"
height="171.55719"
x="43.721401"
- y="276.1973"
+ y="384.1973"
rx="11.072577"
inkscape:export-filename="/home/essen/extend/cowboy/guide/http_req_resp.png"
inkscape:export-xdpi="89.926643"
@@ -155,7 +221,7 @@
y="0"
xlink:href="#g5650"
id="use5654"
- transform="translate(205.03261,-31.336292)"
+ transform="translate(205.03261,76.66371)"
width="744.09448"
height="1052.3622"
inkscape:export-filename="/home/essen/extend/cowboy/guide/http_req_resp.png"
@@ -223,17 +289,6 @@
style="fill:#6d8e41;fill-opacity:1;fill-rule:nonzero;stroke:#6d8e41;stroke-width:0;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0;opacity:0.8"
sodipodi:type="star" />
</g>
- <use
- x="0"
- y="0"
- xlink:href="#use5654"
- id="use5656"
- transform="translate(6.1542801e-7,-87.19819)"
- width="744.09448"
- height="1052.3622"
- inkscape:export-filename="/home/essen/extend/cowboy/guide/http_req_resp.png"
- inkscape:export-xdpi="89.926643"
- inkscape:export-ydpi="89.926643" />
<rect
style="fill:#d1f2a5;fill-opacity:1;fill-rule:nonzero;stroke:#a9ca7d;stroke-width:3;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0"
id="rect5273"
@@ -274,247 +329,215 @@
x="-224.02068"
y="274.53128"
rx="15" />
- <use
- x="0"
- y="0"
- xlink:href="#rect5273-22"
- id="use5355"
- transform="translate(318.97592,-176.5)"
- width="744.09448"
- height="1052.3622"
- inkscape:export-filename="/home/essen/extend/cowboy/guide/http_req_resp.png"
- inkscape:export-xdpi="89.926643"
- inkscape:export-ydpi="89.926643" />
- <use
- x="0"
- y="0"
- xlink:href="#rect5273-7"
- id="use5359"
- transform="translate(318.97597,32.954225)"
- width="744.09448"
- height="1052.3622"
- inkscape:export-filename="/home/essen/extend/cowboy/guide/http_req_resp.png"
- inkscape:export-xdpi="89.926643"
- inkscape:export-ydpi="89.926643" />
- <use
- x="0"
- y="0"
- xlink:href="#use5359"
- id="use5361"
- transform="translate(1.630859e-6,86.769591)"
- width="744.09448"
- height="1052.3622"
- inkscape:export-filename="/home/essen/extend/cowboy/guide/http_req_resp.png"
- inkscape:export-xdpi="89.926643"
- inkscape:export-ydpi="89.926643" />
- <rect
- rx="15"
- y="386.37247"
- x="94.955292"
- height="36.392323"
- width="104.5895"
- id="use5363"
- style="fill:#d1f2a5;fill-opacity:1;fill-rule:nonzero;stroke:#a9ca7d;stroke-width:3;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0" />
- <use
- x="0"
- y="0"
- xlink:href="#use5361"
- id="use5365"
- transform="translate(0,88.97624)"
- width="744.09448"
- height="1052.3622"
- inkscape:export-filename="/home/essen/extend/cowboy/guide/http_req_resp.png"
- inkscape:export-xdpi="89.926643"
- inkscape:export-ydpi="89.926643" />
<text
xml:space="preserve"
- style="font-size:16px;font-style:normal;font-weight:normal;text-align:center;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#77823c;fill-opacity:1;stroke:none;font-family:Sans;-inkscape-font-specification:Sans"
+ style="font-style:normal;font-weight:normal;line-height:0%;font-family:sans-serif;-inkscape-font-specification:Sans;text-align:center;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#77823c;fill-opacity:1;stroke:none"
x="-58.692513"
y="114.39204"
- id="text5371"
- sodipodi:linespacing="125%"><tspan
+ id="text5371"><tspan
sodipodi:role="line"
id="tspan5373"
x="-58.692513"
- y="114.39204">some text</tspan></text>
- <text
- xml:space="preserve"
- style="font-size:16px;font-style:normal;font-weight:normal;text-align:center;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#77823c;fill-opacity:1;stroke:none;font-family:Sans;-inkscape-font-specification:Sans"
- x="146.77734"
- y="147.73293"
- id="text5371-7"
- sodipodi:linespacing="125%"
- inkscape:export-filename="/home/essen/extend/cowboy/guide/http_req_resp.png"
- inkscape:export-xdpi="89.926643"
- inkscape:export-ydpi="89.926643"><tspan
- sodipodi:role="line"
- id="tspan5373-3"
- x="146.77734"
- y="147.73293">acceptor</tspan></text>
- <text
- xml:space="preserve"
- style="font-size:16px;font-style:normal;font-weight:normal;text-align:center;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#77823c;fill-opacity:1;stroke:none;font-family:Sans;-inkscape-font-specification:Sans"
- x="146.53125"
- y="233.42836"
- id="text5371-74"
- sodipodi:linespacing="125%"
- inkscape:export-filename="/home/essen/extend/cowboy/guide/http_req_resp.png"
- inkscape:export-xdpi="89.926643"
- inkscape:export-ydpi="89.926643"><tspan
- sodipodi:role="line"
- id="tspan5373-5"
- x="146.53125"
- y="233.42836">parser</tspan></text>
- <text
- xml:space="preserve"
- style="font-size:16px;font-style:normal;font-weight:normal;text-align:center;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#77823c;fill-opacity:1;stroke:none;font-family:Sans;-inkscape-font-specification:Sans"
- x="146.53125"
- y="323.0921"
- id="text5371-5"
- sodipodi:linespacing="125%"
- inkscape:export-filename="/home/essen/extend/cowboy/guide/http_req_resp.png"
- inkscape:export-xdpi="89.926643"
- inkscape:export-ydpi="89.926643"><tspan
- sodipodi:role="line"
- id="tspan5373-0"
+ y="114.39204"
+ style="font-size:16px;line-height:1.25;font-family:sans-serif">some text</tspan></text>
+ <g
+ id="g3850">
+ <use
+ inkscape:export-ydpi="89.926643"
+ inkscape:export-xdpi="89.926643"
+ inkscape:export-filename="/home/essen/extend/cowboy/guide/http_req_resp.png"
+ height="1052.3622"
+ width="744.09448"
+ transform="translate(318.97597,32.837526)"
+ id="use5359"
+ xlink:href="#rect5273-7"
+ y="0"
+ x="0" />
+ <a
+ id="a3826">
+ <text
+ xml:space="preserve"
+ style="font-style:normal;font-weight:normal;line-height:0%;font-family:sans-serif;-inkscape-font-specification:Sans;text-align:center;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#77823c;fill-opacity:1;stroke:none"
+ x="146.77739"
+ y="145.67879"
+ id="text5371-7"
+ inkscape:export-filename="/home/essen/extend/cowboy/guide/http_req_resp.png"
+ inkscape:export-xdpi="89.926643"
+ inkscape:export-ydpi="89.926643"><tspan
+ sodipodi:role="line"
+ id="tspan5373-3"
+ x="146.77739"
+ y="145.67879"
+ style="font-size:16px;line-height:1.25;font-family:sans-serif">acceptor</tspan></text>
+ </a>
+ </g>
+ <g
+ id="g3860">
+ <use
+ inkscape:export-ydpi="89.926643"
+ inkscape:export-xdpi="89.926643"
+ inkscape:export-filename="/home/essen/extend/cowboy/guide/http_req_resp.png"
+ height="1052.3622"
+ width="744.09448"
+ transform="translate(1.630859e-6,86.777953)"
+ id="use5361"
+ xlink:href="#use5359"
+ y="0"
+ x="0" />
+ <text
+ inkscape:export-ydpi="89.926643"
+ inkscape:export-xdpi="89.926643"
+ inkscape:export-filename="/home/essen/extend/cowboy/guide/http_req_resp.png"
+ id="text5371-74"
+ y="232.91768"
+ x="147.26958"
+ style="font-style:normal;font-weight:normal;line-height:0%;font-family:sans-serif;-inkscape-font-specification:Sans;text-align:center;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#77823c;fill-opacity:1;stroke:none"
+ xml:space="preserve"><tspan
+ id="tspan3770"
+ style="font-size:16px;line-height:1.25;font-family:sans-serif"
+ y="232.91768"
+ x="147.26958"
+ sodipodi:role="line">protocol</tspan></text>
+ </g>
+ <g
+ id="g3904">
+ <use
+ inkscape:export-ydpi="89.926643"
+ inkscape:export-xdpi="89.926643"
+ inkscape:export-filename="/home/essen/extend/cowboy/guide/http_req_resp.png"
+ height="1052.3622"
+ width="744.09448"
+ transform="translate(0,197.08458)"
+ id="use5365"
+ xlink:href="#use5361"
+ y="0"
+ x="0" />
+ <text
+ inkscape:export-ydpi="89.926643"
+ inkscape:export-xdpi="89.926643"
+ inkscape:export-filename="/home/essen/extend/cowboy/guide/http_req_resp.png"
+ id="text5371-5"
+ y="431.0921"
x="146.53125"
- y="323.0921">router</tspan></text>
+ style="font-style:normal;font-weight:normal;line-height:0%;font-family:sans-serif;-inkscape-font-specification:Sans;text-align:center;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#77823c;fill-opacity:1;stroke:none"
+ xml:space="preserve"><tspan
+ style="font-size:16px;line-height:1.25;font-family:sans-serif"
+ y="431.0921"
+ x="146.53125"
+ id="tspan5373-0"
+ sodipodi:role="line">router</tspan></text>
+ </g>
<text
xml:space="preserve"
- style="font-size:16px;font-style:normal;font-weight:normal;text-align:center;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#6d8e41;fill-opacity:1;stroke:none;font-family:Sans;-inkscape-font-specification:Sans"
+ style="font-style:normal;font-weight:normal;line-height:0%;font-family:sans-serif;-inkscape-font-specification:Sans;text-align:center;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#6d8e41;fill-opacity:1;stroke:none"
x="-58.692513"
y="53.112247"
- id="text5371-2"
- sodipodi:linespacing="125%"><tspan
+ id="text5371-2"><tspan
sodipodi:role="line"
id="tspan5373-6"
x="-58.692513"
- y="53.112247">some text</tspan></text>
- <text
- xml:space="preserve"
- style="font-size:16px;font-style:normal;font-weight:normal;text-align:center;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#6d8e41;fill-opacity:1;stroke:none;font-family:Sans;-inkscape-font-specification:Sans"
- x="146.53125"
- y="410.38519"
- id="text5371-2-3-0"
- sodipodi:linespacing="125%"
- inkscape:export-filename="/home/essen/extend/cowboy/guide/http_req_resp.png"
- inkscape:export-xdpi="89.926643"
- inkscape:export-ydpi="89.926643"><tspan
- sodipodi:role="line"
- id="tspan5373-6-7-3"
+ y="53.112247"
+ style="font-size:16px;line-height:1.25;font-family:sans-serif">some text</tspan></text>
+ <g
+ id="g3909">
+ <rect
+ style="fill:#d1f2a5;fill-opacity:1;fill-rule:nonzero;stroke:#a9ca7d;stroke-width:3;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
+ id="use5363"
+ width="104.5895"
+ height="36.392323"
+ x="94.955292"
+ y="494.37244"
+ rx="15" />
+ <text
+ inkscape:export-ydpi="89.926643"
+ inkscape:export-xdpi="89.926643"
+ inkscape:export-filename="/home/essen/extend/cowboy/guide/http_req_resp.png"
+ id="text5371-2-3-0"
+ y="518.38519"
x="146.53125"
- y="410.38519">handler</tspan></text>
+ style="font-style:normal;font-weight:normal;line-height:0%;font-family:sans-serif;-inkscape-font-specification:Sans;text-align:center;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#6d8e41;fill-opacity:1;stroke:none"
+ xml:space="preserve"><tspan
+ style="font-size:16px;line-height:1.25;font-family:sans-serif"
+ y="518.38519"
+ x="146.53125"
+ id="tspan5373-6-7-3"
+ sodipodi:role="line">handler</tspan></text>
+ </g>
<text
xml:space="preserve"
- style="font-size:16px;font-style:normal;font-weight:normal;text-align:center;line-height:125%;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:middle;fill:#6d8e41;fill-opacity:1;stroke:none;font-family:Sans;-inkscape-font-specification:Sans"
- x="-362.30792"
+ style="font-style:normal;font-weight:normal;line-height:0%;font-family:sans-serif;-inkscape-font-specification:Sans;text-align:center;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:middle;fill:#6d8e41;fill-opacity:1;stroke:none"
+ x="-470.30792"
y="63.078125"
id="text5371-2-3-0-7"
- sodipodi:linespacing="125%"
- transform="matrix(0,-1,1,0,0,0)"
+ transform="rotate(-90)"
inkscape:export-filename="/home/essen/extend/cowboy/guide/http_req_resp.png"
inkscape:export-xdpi="89.926643"
inkscape:export-ydpi="89.926643"><tspan
sodipodi:role="line"
id="tspan5373-6-7-3-9"
- x="-362.30792"
- y="63.078125">middlewares</tspan></text>
+ x="-470.30792"
+ y="63.078125"
+ style="font-size:16px;line-height:1.25;font-family:sans-serif">middlewares</tspan></text>
<text
xml:space="preserve"
- style="font-size:16px;font-style:normal;font-weight:normal;text-align:center;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#9b3b1c;fill-opacity:1;stroke:none;font-family:Sans;-inkscape-font-specification:Sans"
+ style="font-style:normal;font-weight:normal;line-height:0%;font-family:sans-serif;-inkscape-font-specification:Sans;text-align:center;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#9b3b1c;fill-opacity:1;stroke:none"
x="-58.692513"
y="236.95154"
- id="text5371-4"
- sodipodi:linespacing="125%"><tspan
+ id="text5371-4"><tspan
sodipodi:role="line"
id="tspan5373-9"
x="-58.692513"
- y="236.95154">some text</tspan></text>
- <text
- xml:space="preserve"
- style="font-size:16px;font-style:normal;font-weight:normal;text-align:center;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#9b3b1c;fill-opacity:1;stroke:none;font-family:Sans;-inkscape-font-specification:Sans"
- x="147.00391"
- y="60.912468"
- id="text5371-4-0"
- sodipodi:linespacing="125%"
- inkscape:export-filename="/home/essen/extend/cowboy/guide/http_req_resp.png"
- inkscape:export-xdpi="89.926643"
- inkscape:export-ydpi="89.926643"><tspan
- sodipodi:role="line"
- id="tspan5373-9-2"
+ y="236.95154"
+ style="font-size:16px;line-height:1.25;font-family:sans-serif">some text</tspan></text>
+ <g
+ id="g3855">
+ <use
+ inkscape:export-ydpi="89.926643"
+ inkscape:export-xdpi="89.926643"
+ inkscape:export-filename="/home/essen/extend/cowboy/guide/http_req_resp.png"
+ height="1052.3622"
+ width="744.09448"
+ transform="translate(318.97592,-176.5)"
+ id="use5355"
+ xlink:href="#rect5273-22"
+ y="0"
+ x="0" />
+ <text
+ inkscape:export-ydpi="89.926643"
+ inkscape:export-xdpi="89.926643"
+ inkscape:export-filename="/home/essen/extend/cowboy/guide/http_req_resp.png"
+ id="text5371-4-0"
+ y="60.912468"
x="147.00391"
- y="60.912468">client</tspan></text>
- <use
- x="0"
- y="0"
- xlink:href="#rect5273-7"
- id="use5668"
- transform="translate(589.05532,122.34788)"
- width="744.09448"
- height="1052.3622"
- inkscape:export-filename="/home/essen/extend/cowboy/guide/http_req_resp.png"
- inkscape:export-xdpi="89.926643"
- inkscape:export-ydpi="89.926643" />
- <use
- x="0"
- y="0"
- xlink:href="#rect5273"
- id="use5670"
- transform="translate(589.05538,270.59134)"
- width="744.09448"
- height="1052.3622"
- inkscape:export-filename="/home/essen/extend/cowboy/guide/http_req_resp.png"
- inkscape:export-xdpi="89.926643"
- inkscape:export-ydpi="89.926643" />
- <use
- x="0"
- y="0"
- xlink:href="#use5355"
- id="use5672"
- transform="translate(270.07946,350.22962)"
- width="744.09448"
- height="1052.3622"
- inkscape:export-filename="/home/essen/extend/cowboy/guide/http_req_resp.png"
- inkscape:export-xdpi="89.926643"
- inkscape:export-ydpi="89.926643" />
- <use
- x="0"
- y="0"
- xlink:href="#text5371-4-0"
- id="use5674"
- transform="translate(270.29655,349.47315)"
- width="744.09448"
- height="1052.3622"
- inkscape:export-filename="/home/essen/extend/cowboy/guide/http_req_resp.png"
- inkscape:export-xdpi="89.926643"
- inkscape:export-ydpi="89.926643" />
- <text
- xml:space="preserve"
- style="font-size:16px;font-style:normal;font-weight:normal;text-align:center;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#77823c;fill-opacity:1;stroke:none;font-family:Sans;-inkscape-font-specification:Sans"
- x="417.30829"
- y="236.73991"
- id="text5371-9"
- sodipodi:linespacing="125%"
- inkscape:export-filename="/home/essen/extend/cowboy/guide/http_req_resp.png"
- inkscape:export-xdpi="89.926643"
- inkscape:export-ydpi="89.926643"><tspan
- sodipodi:role="line"
- id="tspan5373-57"
- x="417.30829"
- y="236.73991">reply</tspan></text>
- <text
- xml:space="preserve"
- style="font-size:16px;font-style:normal;font-weight:normal;text-align:center;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#6d8e41;fill-opacity:1;stroke:none;font-family:Sans;-inkscape-font-specification:Sans"
- x="417.30829"
- y="323.09195"
- id="text5371-2-0"
- sodipodi:linespacing="125%"
- inkscape:export-filename="/home/essen/extend/cowboy/guide/http_req_resp.png"
- inkscape:export-xdpi="89.926643"
- inkscape:export-ydpi="89.926643"><tspan
- sodipodi:role="line"
- id="tspan5373-6-8"
- x="417.30829"
- y="323.09195">onresponse</tspan></text>
+ style="font-style:normal;font-weight:normal;line-height:0%;font-family:sans-serif;-inkscape-font-specification:Sans;text-align:center;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#9b3b1c;fill-opacity:1;stroke:none"
+ xml:space="preserve"><tspan
+ style="font-size:16px;line-height:1.25;font-family:sans-serif"
+ y="60.912468"
+ x="147.00391"
+ id="tspan5373-9-2"
+ sodipodi:role="line">client</tspan></text>
+ </g>
+ <g
+ id="g3865">
+ <rect
+ rx="15"
+ y="297.08545"
+ x="94.955299"
+ height="36.392323"
+ width="104.5895"
+ id="rect5273-3"
+ style="fill:#d1f2a5;fill-opacity:1;fill-rule:nonzero;stroke:#a9ca7d;stroke-width:3;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" />
+ <text
+ id="text5371-2-6"
+ y="320.78552"
+ x="147.50005"
+ style="font-style:normal;font-weight:normal;line-height:0%;font-family:sans-serif;-inkscape-font-specification:Sans;text-align:center;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#6d8e41;fill-opacity:1;stroke:none"
+ xml:space="preserve"><tspan
+ style="font-size:16px;line-height:1.25;font-family:sans-serif"
+ y="320.78552"
+ x="147.50005"
+ id="tspan5373-6-7"
+ sodipodi:role="line">stream</tspan></text>
+ </g>
</g>
</svg>
diff --git a/docs/en/cowboy/2.0/guide/index.html b/docs/en/cowboy/2.0/guide/index.html
index ad2346ca..b7910796 100644
--- a/docs/en/cowboy/2.0/guide/index.html
+++ b/docs/en/cowboy/2.0/guide/index.html
@@ -241,13 +241,6 @@
</p>
</li>
</ul></div>
-<div class="ulist"><ul>
-<li>
-<p>
-<a href="sub_protocols/">Sub protocols</a>
-</p>
-</li>
-</ul></div>
</div>
</div>
<div class="sect1">
diff --git a/docs/en/cowboy/2.0/guide/middlewares/index.html b/docs/en/cowboy/2.0/guide/middlewares/index.html
index 35d9e1c3..bb0a2a0c 100644
--- a/docs/en/cowboy/2.0/guide/middlewares/index.html
+++ b/docs/en/cowboy/2.0/guide/middlewares/index.html
@@ -168,8 +168,8 @@ values. It puts the result of the request handling into <code>result</code>.</p>
- <a style="float:right" href="https://ninenines.eu/docs/en/cowboy/2.0/guide/sub_protocols/">
- Sub protocols
+ <a style="float:right" href="https://ninenines.eu/docs/en/cowboy/2.0/guide/migrating_from_1.0/">
+ Migrating from Cowboy 1.0 to 2.0
</a>
</nav>
diff --git a/docs/en/cowboy/2.0/guide/migrating_from_1.0.asciidoc b/docs/en/cowboy/2.0/guide/migrating_from_1.0.asciidoc
index e9663788..14be1fc4 100644
--- a/docs/en/cowboy/2.0/guide/migrating_from_1.0.asciidoc
+++ b/docs/en/cowboy/2.0/guide/migrating_from_1.0.asciidoc
@@ -54,7 +54,7 @@ Cowboy 2.0 now comes with Erlang.mk templates.
than for the entire listener.
* Websocket permessage-deflate compression is now supported
- via the `websocket_compress` option.
+ via the `compress` option.
* Static file handlers will now correctly find files found
in '.ez' archives.
diff --git a/docs/en/cowboy/2.0/guide/migrating_from_1.0/index.html b/docs/en/cowboy/2.0/guide/migrating_from_1.0/index.html
index 8cfa2dae..c10169c4 100644
--- a/docs/en/cowboy/2.0/guide/migrating_from_1.0/index.html
+++ b/docs/en/cowboy/2.0/guide/migrating_from_1.0/index.html
@@ -139,7 +139,7 @@ Because of the many changes in the internals of Cowboy,
<li>
<p>
Websocket permessage-deflate compression is now supported
- via the <code>websocket_compress</code> option.
+ via the <code>compress</code> option.
</p>
</li>
<li>
@@ -448,8 +448,8 @@ The static file handler has been improved to handle more special
<nav style="margin:1em 0">
- <a style="float:left" href="https://ninenines.eu/docs/en/cowboy/2.0/guide/sub_protocols/">
- Sub protocols
+ <a style="float:left" href="https://ninenines.eu/docs/en/cowboy/2.0/guide/middlewares/">
+ Middlewares
</a>
diff --git a/docs/en/cowboy/2.0/guide/overview.asciidoc b/docs/en/cowboy/2.0/guide/overview.asciidoc
deleted file mode 100644
index 3e5cbb74..00000000
--- a/docs/en/cowboy/2.0/guide/overview.asciidoc
+++ /dev/null
@@ -1,150 +0,0 @@
-[[overview]]
-== Request overview
-
-This chapter explains the different steps a request
-goes through until a response is sent, along with
-details of the Cowboy implementation.
-
-=== Request/response
-
-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.
-
-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.
-
-Requests take the following route in Cowboy:
-
-image::http_req_resp.png[HTTP request/response flowchart]
-
-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.
-
-The `acceptor` is the part of the server that accepts
-the connection and create an Erlang process to handle
-it. The `parser` then starts reading from the socket
-and handling requests as they come until the socket
-is closed.
-
-A response may be sent at many different points in the
-life of the request. If Cowboy can't parse the request,
-it gives up with an error response. If the router can't
-find the resource, it sends a not found error. Your
-own code can of course send a response at any time.
-
-When a response is sent, you can optionally modify it
-or act upon it by enabling the `onresponse` hook. By
-default the response is sent directly to the client.
-
-=== And then?
-
-Behavior depends on what protocol is in use.
-
-HTTP/1.0 can only process one request per connection,
-so Cowboy will close the connection immediately after
-it sends the response.
-
-HTTP/1.1 allows the client to request that the server
-keeps the connection alive. This mechanism is described
-in the next section.
-
-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.
-
-=== Keep-alive (HTTP/1.1)
-
-With HTTP/1.1, the connection may be left open for
-subsequent requests to come. This mechanism is called
-`keep-alive`.
-
-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.
-
-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 `connection: close` header, it will
-not override it and will close the connection as soon
-as the reply is sent.
-
-This snippet will force Cowboy to close the connection.
-
-[source,erlang]
-----
-Req2 = cowboy_req:reply(200, [
- {<<"connection">>, <<"close">>},
-], <<"Closing the socket in 3.. 2.. 1..">>, Req).
-----
-
-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
-`max_keepalive` configuration value when starting an
-HTTP listener.
-
-[source,erlang]
-----
-cowboy:start_http(my_http_listener, 100, [{port, 8080}], [
- {env, [{dispatch, Dispatch}]},
- {max_keepalive, 5}
-]).
-----
-
-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 `terminate/3` function can
-be used for this purpose.
-
-=== Pipelining (HTTP/1.1)
-
-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.
-
-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.
-
-This is handled automatically by the server.
-
-=== Asynchronous requests (HTTP/2)
-
-In HTTP/2, the client can send a request at any time.
-And the server can send a response at any time too.
-
-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.
-
-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.
-
-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.
diff --git a/docs/en/cowboy/2.0/guide/overview/index.html b/docs/en/cowboy/2.0/guide/overview/index.html
deleted file mode 100644
index fb4e5cee..00000000
--- a/docs/en/cowboy/2.0/guide/overview/index.html
+++ /dev/null
@@ -1,297 +0,0 @@
-<!DOCTYPE html>
-<html lang="en">
-
-<head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <meta name="description" content="">
- <meta name="author" content="Loïc Hoguin based on a design from (Soft10) Pol Cámara">
-
- <meta name="generator" content="Hugo 0.17" />
-
- <title>Nine Nines: Request overview</title>
-
- <link href='https://fonts.googleapis.com/css?family=Open+Sans:400,700,400italic' rel='stylesheet' type='text/css'>
- <link href="/css/99s.css?r=1" rel="stylesheet">
-
- <link rel="shortcut icon" href="/img/ico/favicon.ico">
- <link rel="apple-touch-icon-precomposed" sizes="114x114" href="/img/ico/apple-touch-icon-114.png">
- <link rel="apple-touch-icon-precomposed" sizes="72x72" href="/img/ico/apple-touch-icon-72.png">
- <link rel="apple-touch-icon-precomposed" href="/img/ico/apple-touch-icon-57.png">
-
-
-</head>
-
-
-<body class="">
- <header id="page-head">
- <div id="topbar" class="container">
- <div class="row">
- <div class="span2">
- <h1 id="logo"><a href="/" title="99s">99s</a></h1>
- </div>
- <div class="span10">
-
- <div id="side-header">
- <nav>
- <ul>
- <li><a title="Hear my thoughts" href="/articles">Articles</a></li>
- <li><a title="Watch my talks" href="/talks">Talks</a></li>
- <li class="active"><a title="Read the docs" href="/docs">Documentation</a></li>
- <li><a title="Request my services" href="/services">Consulting & Training</a></li>
- </ul>
- </nav>
- <ul id="social">
- <li>
- <a href="https://github.com/ninenines" title="Check my Github repositories"><img src="/img/ico_github.png" data-hover="/img/ico_github_alt.png" alt="Github"></a>
- </li>
- <li>
- <a title="Keep in touch!" href="http://twitter.com/lhoguin"><img src="/img/ico_microblog.png" data-hover="/img/ico_microblog_alt.png"></a>
- </li>
- <li>
- <a title="Contact me" href="mailto:[email protected]"><img src="/img/ico_mail.png" data-hover="/img/ico_mail_alt.png"></a>
- </li>
- </ul>
- </div>
- </div>
- </div>
- </div>
-
-
-</header>
-
-<div id="contents" class="two_col">
-<div class="container">
-<div class="row">
-<div id="docs" class="span9 maincol">
-
-<h1 class="lined-header"><span>Request overview</span></h1>
-
-<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>
-
-
-
-
-
-
-
- <nav style="margin:1em 0">
-
- <a style="float:left" href="https://ninenines.eu/docs/en/cowboy/2.0/guide/hooks/">
- Hooks
- </a>
-
-
-
- </nav>
-
-
-
-
-</div>
-
-<div class="span3 sidecol">
-
-
-<h3>
- Cowboy
- 2.0
-
- User Guide
-</h3>
-
-<ul>
-
- <li><a href="/docs/en/cowboy/2.0/guide">User Guide</a></li>
-
-
- <li><a href="/docs/en/cowboy/2.0/manual">Function Reference</a></li>
-
-
-</ul>
-
-<h4 id="docs-nav">Navigation</h4>
-
-<h4>Version select</h4>
-<ul>
-
-
-
- <li><a href="/docs/en/cowboy/2.0/guide">2.0</a></li>
-
- <li><a href="/docs/en/cowboy/1.0/guide">1.0</a></li>
-
-</ul>
-
-</div>
-</div>
-</div>
-</div>
-
- <footer>
- <div class="container">
- <div class="row">
- <div class="span6">
- <p id="scroll-top"><a href="#">↑ Scroll to top</a></p>
- <nav>
- <ul>
- <li><a href="mailto:[email protected]" title="Contact us">Contact us</a></li><li><a href="https://github.com/ninenines/ninenines.github.io" title="Github repository">Contribute to this site</a></li>
- </ul>
- </nav>
- </div>
- <div class="span6 credits">
- <p><img src="/img/footer_logo.png"></p>
- <p>Copyright &copy; Loïc Hoguin 2012-2016</p>
- </div>
- </div>
- </div>
- </footer>
-
-
- <script src="/js/custom.js"></script>
- </body>
-</html>
-
-
diff --git a/docs/en/cowboy/2.0/guide/specs.asciidoc b/docs/en/cowboy/2.0/guide/specs.asciidoc
index 3bcd45e1..db4abe45 100644
--- a/docs/en/cowboy/2.0/guide/specs.asciidoc
+++ b/docs/en/cowboy/2.0/guide/specs.asciidoc
@@ -80,6 +80,7 @@ for or related to HTTP.
* https://tools.ietf.org/html/rfc7804[RFC 7804]: Salted Challenge Response HTTP Authentication Mechanism
* https://tools.ietf.org/html/rfc7838[RFC 7838]: HTTP Alternative Services
* https://tools.ietf.org/html/rfc7932[RFC 7932]: Brotli Compressed Data Format
+* https://tools.ietf.org/html/rfc7936[RFC 7936]: Clarifying Registry Procedures for the WebSocket Subprotocol Name Registry
* https://tools.ietf.org/html/rfc8053[RFC 8053]: HTTP Authentication Extensions for Interactive Clients
* https://tools.ietf.org/html/rfc8164[RFC 8164]: Opportunistic Security for HTTP/2
* https://tools.ietf.org/html/rfc8188[RFC 8188]: Encrypted Content-Encoding for HTTP
diff --git a/docs/en/cowboy/2.0/guide/specs/index.html b/docs/en/cowboy/2.0/guide/specs/index.html
index 7a8135c2..be0d89be 100644
--- a/docs/en/cowboy/2.0/guide/specs/index.html
+++ b/docs/en/cowboy/2.0/guide/specs/index.html
@@ -427,6 +427,11 @@ for or related to HTTP.</p></div>
</li>
<li>
<p>
+<a href="https://tools.ietf.org/html/rfc7936">RFC 7936</a>: Clarifying Registry Procedures for the WebSocket Subprotocol Name Registry
+</p>
+</li>
+<li>
+<p>
<a href="https://tools.ietf.org/html/rfc8053">RFC 8053</a>: HTTP Authentication Extensions for Interactive Clients
</p>
</li>
@@ -905,10 +910,6 @@ for or related to HTTP.</p></div>
- <a style="float:right" href="https://ninenines.eu/docs/en/cowboy/2.0/guide/architecture/">
- Architecture
- </a>
-
</nav>
diff --git a/docs/en/cowboy/2.0/guide/streams.asciidoc b/docs/en/cowboy/2.0/guide/streams.asciidoc
index 243e5815..841a9712 100644
--- a/docs/en/cowboy/2.0/guide/streams.asciidoc
+++ b/docs/en/cowboy/2.0/guide/streams.asciidoc
@@ -1,15 +1,65 @@
[[streams]]
== Streams
-Placeholder chapter.
+A stream is the set of messages that form an HTTP
+request/response pair.
-Streams are a new feature in Cowboy 2.0 that requires
-a little more tweaking before they can be generally
-useful. This chapter will be made available in a future
-pre-release.
+The term stream comes from HTTP/2. In Cowboy, it is
+also used when talking about HTTP/1.1 or HTTP/1.0.
+It should not be confused with streaming the request
+or response body.
-Streams are meant to replace hooks. The relevant chapters
-for Cowboy 1.0 were:
+All versions of HTTP allow clients to initiate
+streams. HTTP/2 is the only one also allowing servers,
+through its server push feature. Both client and
+server-initiated streams go through the same process
+in Cowboy.
-* xref:hooks[Hooks]
-* xref:broken_clients[Dealing with broken clients]
+=== Stream handlers
+
+Stream handlers must implement five different callbacks.
+Four of them are directly related; one is special.
+
+All callbacks receives the stream ID as first argument.
+
+Most of them can return a list of commands to be executed
+by Cowboy. When callbacks are chained, it is possible to
+intercept and modify these commands. This can be useful
+for modifying responses for example.
+
+The `init/3` callback is invoked when a new request
+comes in. It receives the Req object and the protocol options
+for this listener.
+
+The `data/4` callback is invoked when data from the request
+body is received. It receives both this data and a flag
+indicating whether more is to be expected.
+
+The `info/3` callback is invoked when an Erlang message is
+received for this stream. They will typically be messages
+sent by the request process.
+
+Finally the `terminate/3` callback is invoked with the
+terminate reason for the stream. The return value is ignored.
+Note that as with all terminate callbacks in Erlang, there
+is no strong guarantee that it will be called.
+
+The special callback `early_error/5` is called when an error
+occurs before the request headers were fully received and
+Cowboy is sending a response. It receives the partial Req
+object, the error reason, the protocol options and the response
+Cowboy will send. This response must be returned, possibly
+modified.
+
+=== Built-in handlers
+
+Cowboy comes with two handlers.
+
+`cowboy_stream_h` is the default stream handler.
+It is the core of much of the functionality of Cowboy.
+All chains of stream handlers should call it last.
+
+`cowboy_compress_h` will automatically compress
+responses when possible. It is not enabled by default.
+It is a good example for writing your own handlers
+that will modify responses.
diff --git a/docs/en/cowboy/2.0/guide/streams/index.html b/docs/en/cowboy/2.0/guide/streams/index.html
index a73d9928..4641b9b1 100644
--- a/docs/en/cowboy/2.0/guide/streams/index.html
+++ b/docs/en/cowboy/2.0/guide/streams/index.html
@@ -67,25 +67,61 @@
<h1 class="lined-header"><span>Streams</span></h1>
-<div class="paragraph"><p>Placeholder chapter.</p></div>
-<div class="paragraph"><p>Streams are a new feature in Cowboy 2.0 that requires
-a little more tweaking before they can be generally
-useful. This chapter will be made available in a future
-pre-release.</p></div>
-<div class="paragraph"><p>Streams are meant to replace hooks. The relevant chapters
-for Cowboy 1.0 were:</p></div>
-<div class="ulist"><ul>
-<li>
-<p>
-<a href="../hooks">Hooks</a>
-</p>
-</li>
-<li>
-<p>
-<a href="../broken_clients">Dealing with broken clients</a>
-</p>
-</li>
-</ul></div>
+<div class="paragraph"><p>A stream is the set of messages that form an HTTP
+request/response pair.</p></div>
+<div class="paragraph"><p>The term stream comes from HTTP/2. In Cowboy, it is
+also used when talking about HTTP/1.1 or HTTP/1.0.
+It should not be confused with streaming the request
+or response body.</p></div>
+<div class="paragraph"><p>All versions of HTTP allow clients to initiate
+streams. HTTP/2 is the only one also allowing servers,
+through its server push feature. Both client and
+server-initiated streams go through the same process
+in Cowboy.</p></div>
+<div class="sect1">
+<h2 id="_stream_handlers">Stream handlers</h2>
+<div class="sectionbody">
+<div class="paragraph"><p>Stream handlers must implement five different callbacks.
+Four of them are directly related; one is special.</p></div>
+<div class="paragraph"><p>All callbacks receives the stream ID as first argument.</p></div>
+<div class="paragraph"><p>Most of them can return a list of commands to be executed
+by Cowboy. When callbacks are chained, it is possible to
+intercept and modify these commands. This can be useful
+for modifying responses for example.</p></div>
+<div class="paragraph"><p>The <code>init/3</code> callback is invoked when a new request
+comes in. It receives the Req object and the protocol options
+for this listener.</p></div>
+<div class="paragraph"><p>The <code>data/4</code> callback is invoked when data from the request
+body is received. It receives both this data and a flag
+indicating whether more is to be expected.</p></div>
+<div class="paragraph"><p>The <code>info/3</code> callback is invoked when an Erlang message is
+received for this stream. They will typically be messages
+sent by the request process.</p></div>
+<div class="paragraph"><p>Finally the <code>terminate/3</code> callback is invoked with the
+terminate reason for the stream. The return value is ignored.
+Note that as with all terminate callbacks in Erlang, there
+is no strong guarantee that it will be called.</p></div>
+<div class="paragraph"><p>The special callback <code>early_error/5</code> is called when an error
+occurs before the request headers were fully received and
+Cowboy is sending a response. It receives the partial Req
+object, the error reason, the protocol options and the response
+Cowboy will send. This response must be returned, possibly
+modified.</p></div>
+</div>
+</div>
+<div class="sect1">
+<h2 id="_built_in_handlers">Built-in handlers</h2>
+<div class="sectionbody">
+<div class="paragraph"><p>Cowboy comes with two handlers.</p></div>
+<div class="paragraph"><p><code>cowboy_stream_h</code> is the default stream handler.
+It is the core of much of the functionality of Cowboy.
+All chains of stream handlers should call it last.</p></div>
+<div class="paragraph"><p><code>cowboy_compress_h</code> will automatically compress
+responses when possible. It is not enabled by default.
+It is a good example for writing your own handlers
+that will modify responses.</p></div>
+</div>
+</div>
diff --git a/docs/en/cowboy/2.0/guide/sub_protocols.asciidoc b/docs/en/cowboy/2.0/guide/sub_protocols.asciidoc
deleted file mode 100644
index 83fa975c..00000000
--- a/docs/en/cowboy/2.0/guide/sub_protocols.asciidoc
+++ /dev/null
@@ -1,73 +0,0 @@
-[[sub_protocols]]
-== Sub protocols
-
-Sub protocols are used for creating new types of handlers that
-provide extra functionality in a reusable way. Cowboy uses this
-mechanism to provide its loop, REST and Websocket handlers.
-
-This chapter will explain how to create your own sub protocols
-and handler types.
-
-=== Usage
-
-To switch to a sub protocol, the `init/2` callback must return
-the name of the sub protocol module. Everything past this point
-is handled by the sub protocol.
-
-[source,erlang]
-----
-init(Req, State) ->
- {cowboy_websocket, Req, State}.
-----
-
-The returned tuple may also have a fourth element containing
-options for the sub protocol. No option is universal. While
-it will usually be a map of options, it doesn't have to be.
-For example loop handlers accept the atom `hibernate`.
-
-The following snippet switches to the `my_protocol` sub
-protocol, sets the timeout value to 5 seconds and enables
-hibernation:
-
-[source,erlang]
-----
-init(Req, State) ->
- {my_protocol, Req, State, #{
- timeout => 5000,
- compress => true}}.
-----
-
-Sub protocols should ignore unknown options so as to not waste
-resources doing unnecessary validation.
-
-=== Upgrade
-
-After the `init/2` function returns, Cowboy will call either
-the `upgrade/4` or the `upgrade/5` function. The former is called
-when no options were given; the latter when they were given.
-
-The function is named `upgrade` because it mimics the mechanism
-of HTTP protocol upgrades. For some sub protocols, like Websocket,
-an actual upgrade is performed. For others, like REST, this is
-only an upgrade at Cowboy's level and the client has nothing to
-do about it.
-
-The upgrade callback receives the Req object, the middleware
-environment, the handler and its state, and for `upgrade/5`
-also the aformentioned options.
-
-[source,erlang]
-----
-upgrade(Req, Env, Handler, State) ->
- %% Sub protocol code here.
-
-upgrade(Req, Env, Handler, State, Opts) ->
- %% Sub protocol code here.
-----
-
-These callbacks are expected to behave like middlewares and to
-return an updated environment and Req object.
-
-Sub protocols are expected to call the `cowboy_handler:terminate/4`
-function when they terminate. This function will make sure that
-the optional `terminate/3` callback is called, if present.
diff --git a/docs/en/cowboy/2.0/guide/sub_protocols/index.html b/docs/en/cowboy/2.0/guide/sub_protocols/index.html
deleted file mode 100644
index 0b4f55ee..00000000
--- a/docs/en/cowboy/2.0/guide/sub_protocols/index.html
+++ /dev/null
@@ -1,227 +0,0 @@
-<!DOCTYPE html>
-<html lang="en">
-
-<head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <meta name="description" content="">
- <meta name="author" content="Loïc Hoguin based on a design from (Soft10) Pol Cámara">
-
- <meta name="generator" content="Hugo 0.17" />
-
- <title>Nine Nines: Sub protocols</title>
-
- <link href='https://fonts.googleapis.com/css?family=Open+Sans:400,700,400italic' rel='stylesheet' type='text/css'>
- <link href="/css/99s.css?r=1" rel="stylesheet">
-
- <link rel="shortcut icon" href="/img/ico/favicon.ico">
- <link rel="apple-touch-icon-precomposed" sizes="114x114" href="/img/ico/apple-touch-icon-114.png">
- <link rel="apple-touch-icon-precomposed" sizes="72x72" href="/img/ico/apple-touch-icon-72.png">
- <link rel="apple-touch-icon-precomposed" href="/img/ico/apple-touch-icon-57.png">
-
-
-</head>
-
-
-<body class="">
- <header id="page-head">
- <div id="topbar" class="container">
- <div class="row">
- <div class="span2">
- <h1 id="logo"><a href="/" title="99s">99s</a></h1>
- </div>
- <div class="span10">
-
- <div id="side-header">
- <nav>
- <ul>
- <li><a title="Hear my thoughts" href="/articles">Articles</a></li>
- <li><a title="Watch my talks" href="/talks">Talks</a></li>
- <li class="active"><a title="Read the docs" href="/docs">Documentation</a></li>
- <li><a title="Request my services" href="/services">Consulting & Training</a></li>
- </ul>
- </nav>
- <ul id="social">
- <li>
- <a href="https://github.com/ninenines" title="Check my Github repositories"><img src="/img/ico_github.png" data-hover="/img/ico_github_alt.png" alt="Github"></a>
- </li>
- <li>
- <a title="Keep in touch!" href="http://twitter.com/lhoguin"><img src="/img/ico_microblog.png" data-hover="/img/ico_microblog_alt.png"></a>
- </li>
- <li>
- <a title="Contact me" href="mailto:[email protected]"><img src="/img/ico_mail.png" data-hover="/img/ico_mail_alt.png"></a>
- </li>
- </ul>
- </div>
- </div>
- </div>
- </div>
-
-
-</header>
-
-<div id="contents" class="two_col">
-<div class="container">
-<div class="row">
-<div id="docs" class="span9 maincol">
-
-<h1 class="lined-header"><span>Sub protocols</span></h1>
-
-<div class="paragraph"><p>Sub protocols are used for creating new types of handlers that
-provide extra functionality in a reusable way. Cowboy uses this
-mechanism to provide its loop, REST and Websocket handlers.</p></div>
-<div class="paragraph"><p>This chapter will explain how to create your own sub protocols
-and handler types.</p></div>
-<div class="sect1">
-<h2 id="_usage">Usage</h2>
-<div class="sectionbody">
-<div class="paragraph"><p>To switch to a sub protocol, the <code>init/2</code> callback must return
-the name of the sub protocol module. Everything past this point
-is handled by the sub protocol.</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">init</span></span>(<span style="color: #009900">Req</span>, <span style="color: #009900">State</span>) <span style="color: #990000">-&gt;</span>
- {<span style="color: #FF6600">cowboy_websocket</span>, <span style="color: #009900">Req</span>, <span style="color: #009900">State</span>}<span style="color: #990000">.</span></tt></pre></div></div>
-<div class="paragraph"><p>The returned tuple may also have a fourth element containing
-options for the sub protocol. No option is universal. While
-it will usually be a map of options, it doesn&#8217;t have to be.
-For example loop handlers accept the atom <code>hibernate</code>.</p></div>
-<div class="paragraph"><p>The following snippet switches to the <code>my_protocol</code> sub
-protocol, sets the timeout value to 5 seconds and enables
-hibernation:</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">init</span></span>(<span style="color: #009900">Req</span>, <span style="color: #009900">State</span>) <span style="color: #990000">-&gt;</span>
- {<span style="color: #FF6600">my_protocol</span>, <span style="color: #009900">Req</span>, <span style="color: #009900">State</span>, #{
- <span style="color: #0000FF">timeout</span> <span style="color: #990000">=&gt;</span> <span style="color: #993399">5000</span>,
- <span style="color: #0000FF">compress</span> <span style="color: #990000">=&gt;</span> <span style="color: #000080">true</span>}}<span style="color: #990000">.</span></tt></pre></div></div>
-<div class="paragraph"><p>Sub protocols should ignore unknown options so as to not waste
-resources doing unnecessary validation.</p></div>
-</div>
-</div>
-<div class="sect1">
-<h2 id="_upgrade">Upgrade</h2>
-<div class="sectionbody">
-<div class="paragraph"><p>After the <code>init/2</code> function returns, Cowboy will call either
-the <code>upgrade/4</code> or the <code>upgrade/5</code> function. The former is called
-when no options were given; the latter when they were given.</p></div>
-<div class="paragraph"><p>The function is named <code>upgrade</code> because it mimics the mechanism
-of HTTP protocol upgrades. For some sub protocols, like Websocket,
-an actual upgrade is performed. For others, like REST, this is
-only an upgrade at Cowboy&#8217;s level and the client has nothing to
-do about it.</p></div>
-<div class="paragraph"><p>The upgrade callback receives the Req object, the middleware
-environment, the handler and its state, and for <code>upgrade/5</code>
-also the aformentioned options.</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">upgrade</span></span>(<span style="color: #009900">Req</span>, <span style="color: #009900">Env</span>, <span style="color: #009900">Handler</span>, <span style="color: #009900">State</span>) <span style="color: #990000">-&gt;</span>
- <span style="font-style: italic"><span style="color: #9A1900">%% Sub protocol code here.</span></span>
-
-<span style="font-weight: bold"><span style="color: #000000">upgrade</span></span>(<span style="color: #009900">Req</span>, <span style="color: #009900">Env</span>, <span style="color: #009900">Handler</span>, <span style="color: #009900">State</span>, <span style="color: #009900">Opts</span>) <span style="color: #990000">-&gt;</span>
- <span style="font-style: italic"><span style="color: #9A1900">%% Sub protocol code here.</span></span></tt></pre></div></div>
-<div class="paragraph"><p>These callbacks are expected to behave like middlewares and to
-return an updated environment and Req object.</p></div>
-<div class="paragraph"><p>Sub protocols are expected to call the <code>cowboy_handler:terminate/4</code>
-function when they terminate. This function will make sure that
-the optional <code>terminate/3</code> callback is called, if present.</p></div>
-</div>
-</div>
-
-
-
-
-
-
-
- <nav style="margin:1em 0">
-
- <a style="float:left" href="https://ninenines.eu/docs/en/cowboy/2.0/guide/middlewares/">
- Middlewares
- </a>
-
-
-
- <a style="float:right" href="https://ninenines.eu/docs/en/cowboy/2.0/guide/migrating_from_1.0/">
- Migrating from Cowboy 1.0 to 2.0
- </a>
-
- </nav>
-
-
-
-
-</div>
-
-<div class="span3 sidecol">
-
-
-<h3>
- Cowboy
- 2.0
-
- User Guide
-</h3>
-
-<ul>
-
- <li><a href="/docs/en/cowboy/2.0/guide">User Guide</a></li>
-
-
- <li><a href="/docs/en/cowboy/2.0/manual">Function Reference</a></li>
-
-
-</ul>
-
-<h4 id="docs-nav">Navigation</h4>
-
-<h4>Version select</h4>
-<ul>
-
-
-
- <li><a href="/docs/en/cowboy/2.0/guide">2.0</a></li>
-
- <li><a href="/docs/en/cowboy/1.0/guide">1.0</a></li>
-
-</ul>
-
-</div>
-</div>
-</div>
-</div>
-
- <footer>
- <div class="container">
- <div class="row">
- <div class="span6">
- <p id="scroll-top"><a href="#">↑ Scroll to top</a></p>
- <nav>
- <ul>
- <li><a href="mailto:[email protected]" title="Contact us">Contact us</a></li><li><a href="https://github.com/ninenines/ninenines.github.io" title="Github repository">Contribute to this site</a></li>
- </ul>
- </nav>
- </div>
- <div class="span6 credits">
- <p><img src="/img/footer_logo.png"></p>
- <p>Copyright &copy; Loïc Hoguin 2012-2016</p>
- </div>
- </div>
- </div>
- </footer>
-
-
- <script src="/js/custom.js"></script>
- </body>
-</html>
-
-
diff --git a/docs/en/cowboy/2.0/manual/cowboy_sub_protocol/index.html b/docs/en/cowboy/2.0/manual/cowboy_sub_protocol/index.html
deleted file mode 100644
index 19bede73..00000000
--- a/docs/en/cowboy/2.0/manual/cowboy_sub_protocol/index.html
+++ /dev/null
@@ -1,221 +0,0 @@
-<!DOCTYPE html>
-<html lang="en">
-
-<head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <meta name="description" content="">
- <meta name="author" content="Loïc Hoguin based on a design from (Soft10) Pol Cámara">
-
- <meta name="generator" content="Hugo 0.17" />
-
- <title>Nine Nines: cowboy_sub_protocol(3)</title>
-
- <link href='https://fonts.googleapis.com/css?family=Open+Sans:400,700,400italic' rel='stylesheet' type='text/css'>
- <link href="/css/99s.css?r=1" rel="stylesheet">
-
- <link rel="shortcut icon" href="/img/ico/favicon.ico">
- <link rel="apple-touch-icon-precomposed" sizes="114x114" href="/img/ico/apple-touch-icon-114.png">
- <link rel="apple-touch-icon-precomposed" sizes="72x72" href="/img/ico/apple-touch-icon-72.png">
- <link rel="apple-touch-icon-precomposed" href="/img/ico/apple-touch-icon-57.png">
-
-
-</head>
-
-
-<body class="">
- <header id="page-head">
- <div id="topbar" class="container">
- <div class="row">
- <div class="span2">
- <h1 id="logo"><a href="/" title="99s">99s</a></h1>
- </div>
- <div class="span10">
-
- <div id="side-header">
- <nav>
- <ul>
- <li><a title="Hear my thoughts" href="/articles">Articles</a></li>
- <li><a title="Watch my talks" href="/talks">Talks</a></li>
- <li class="active"><a title="Read the docs" href="/docs">Documentation</a></li>
- <li><a title="Request my services" href="/services">Consulting & Training</a></li>
- </ul>
- </nav>
- <ul id="social">
- <li>
- <a href="https://github.com/ninenines" title="Check my Github repositories"><img src="/img/ico_github.png" data-hover="/img/ico_github_alt.png" alt="Github"></a>
- </li>
- <li>
- <a title="Keep in touch!" href="http://twitter.com/lhoguin"><img src="/img/ico_microblog.png" data-hover="/img/ico_microblog_alt.png"></a>
- </li>
- <li>
- <a title="Contact me" href="mailto:[email protected]"><img src="/img/ico_mail.png" data-hover="/img/ico_mail_alt.png"></a>
- </li>
- </ul>
- </div>
- </div>
- </div>
- </div>
-
-
-</header>
-
-<div id="contents" class="two_col">
-<div class="container">
-<div class="row">
-<div id="docs" class="span9 maincol">
-
-<h1 class="lined-header"><span>cowboy_sub_protocol(3)</span></h1>
-
-<div class="sect1">
-<h2 id="_name">Name</h2>
-<div class="sectionbody">
-<div class="paragraph"><p>cowboy_sub_protocol - sub protocol</p></div>
-</div>
-</div>
-<div class="sect1">
-<h2 id="_description">Description</h2>
-<div class="sectionbody">
-<div class="paragraph"><p>The <code>cowboy_sub_protocol</code> behaviour defines the interface used
-by modules that implement a protocol on top of HTTP.</p></div>
-</div>
-</div>
-<div class="sect1">
-<h2 id="_callbacks">Callbacks</h2>
-<div class="sectionbody">
-<div class="sect2">
-<h3 id="_upgrade_req_env_handler_handleropts_8594_ok_req_env_suspend_module_function_args_stop_req">upgrade(Req, Env, Handler, HandlerOpts) &#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">
-Handler = module()
-</dt>
-<dd>
-<p>
-Handler module.
-</p>
-</dd>
-<dt class="hdlist1">
-Opts = any()
-</dt>
-<dd>
-<p>
-Handler options.
-</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>Upgrade the protocol.</p></div>
-<div class="paragraph"><p>Please refer to the <code>cowboy_middleware</code> manual for a
-description of the return values.</p></div>
-</div>
-</div>
-</div>
-
-
-
-
-
-</div>
-
-<div class="span3 sidecol">
-
-
-<h3>
- Cowboy
- 2.0
- Function Reference
-
-</h3>
-
-<ul>
-
- <li><a href="/docs/en/cowboy/2.0/guide">User Guide</a></li>
-
-
- <li><a href="/docs/en/cowboy/2.0/manual">Function Reference</a></li>
-
-
-</ul>
-
-<h4 id="docs-nav">Navigation</h4>
-
-<h4>Version select</h4>
-<ul>
-
-
-
- <li><a href="/docs/en/cowboy/2.0/manual">2.0</a></li>
-
- <li><a href="/docs/en/cowboy/1.0/manual">1.0</a></li>
-
-</ul>
-
-</div>
-</div>
-</div>
-</div>
-
- <footer>
- <div class="container">
- <div class="row">
- <div class="span6">
- <p id="scroll-top"><a href="#">↑ Scroll to top</a></p>
- <nav>
- <ul>
- <li><a href="mailto:[email protected]" title="Contact us">Contact us</a></li><li><a href="https://github.com/ninenines/ninenines.github.io" title="Github repository">Contribute to this site</a></li>
- </ul>
- </nav>
- </div>
- <div class="span6 credits">
- <p><img src="/img/footer_logo.png"></p>
- <p>Copyright &copy; Loïc Hoguin 2012-2016</p>
- </div>
- </div>
- </div>
- </footer>
-
-
- <script src="/js/custom.js"></script>
- </body>
-</html>
-
-
diff --git a/docs/index.xml b/docs/index.xml
index 29522471..c2541dc9 100644
--- a/docs/index.xml
+++ b/docs/index.xml
@@ -357,13 +357,6 @@ environment configuration parameters.&lt;/p&gt;&lt;/div&gt;
&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;&lt;/div&gt;
-&lt;div class=&#34;ulist&#34;&gt;&lt;ul&gt;
-&lt;li&gt;
-&lt;p&gt;
-&lt;a href=&#34;sub_protocols/&#34;&gt;Sub protocols&lt;/a&gt;
-&lt;/p&gt;
-&lt;/li&gt;
-&lt;/ul&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&#34;sect1&#34;&gt;
diff --git a/donate/index.html b/donate/index.html
index 0138efb2..1d3b816a 100644
--- a/donate/index.html
+++ b/donate/index.html
@@ -474,18 +474,6 @@ and Erlang.mk is fantastic:</p></div>
-
-
-
-
-
-
-
-
-
-
-
-
</div>
</div>
</div>
diff --git a/index.html b/index.html
index 90b1343d..3833e88d 100644
--- a/index.html
+++ b/index.html
@@ -616,18 +616,6 @@ or buy <a href="/articles/erlanger-playbook">The Erlanger Playbook</a></p></div>
-
-
-
-
-
-
-
-
-
-
-
-
</div>
</div>
diff --git a/services/index.html b/services/index.html
index b1b1a6c9..d42398ce 100644
--- a/services/index.html
+++ b/services/index.html
@@ -559,18 +559,6 @@ and Erlang.mk is fantastic:</p></div>
-
-
-
-
-
-
-
-
-
-
-
-
</div>
</div>
</div>
diff --git a/sitemap.xml b/sitemap.xml
index 963fc92b..58ebeba6 100644
--- a/sitemap.xml
+++ b/sitemap.xml
@@ -415,10 +415,6 @@
</url>
<url>
- <loc>https://ninenines.eu/docs/en/cowboy/2.0/manual/cowboy_sub_protocol/</loc>
- </url>
-
- <url>
<loc>https://ninenines.eu/docs/en/cowboy/2.0/manual/cowboy_websocket/</loc>
</url>
@@ -767,10 +763,6 @@
</url>
<url>
- <loc>https://ninenines.eu/docs/en/cowboy/2.0/guide/sub_protocols/</loc>
- </url>
-
- <url>
<loc>https://ninenines.eu/docs/en/cowboy/2.0/guide/migrating_from_1.0/</loc>
</url>
@@ -778,20 +770,4 @@
<loc>https://ninenines.eu/docs/en/cowboy/2.0/guide/specs/</loc>
</url>
- <url>
- <loc>https://ninenines.eu/docs/en/cowboy/2.0/guide/architecture/</loc>
- </url>
-
- <url>
- <loc>https://ninenines.eu/docs/en/cowboy/2.0/guide/broken_clients/</loc>
- </url>
-
- <url>
- <loc>https://ninenines.eu/docs/en/cowboy/2.0/guide/hooks/</loc>
- </url>
-
- <url>
- <loc>https://ninenines.eu/docs/en/cowboy/2.0/guide/overview/</loc>
- </url>
-
</urlset> \ No newline at end of file