summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2017-12-11 12:45:53 +0100
committerLoïc Hoguin <[email protected]>2017-12-11 12:45:53 +0100
commit73f7713f7138b8e3a80122e6b7d446e8ef3bbb39 (patch)
tree56047f5b62eb092d6ea158414339c4b21d096ffe
parentbc12c6542bd5cb11e33679e7d6350b185954f691 (diff)
downloadninenines.eu-73f7713f7138b8e3a80122e6b7d446e8ef3bbb39.tar.gz
ninenines.eu-73f7713f7138b8e3a80122e6b7d446e8ef3bbb39.tar.bz2
ninenines.eu-73f7713f7138b8e3a80122e6b7d446e8ef3bbb39.zip
Update documentation
-rw-r--r--docs/en/cowboy/2.2/guide/resp.asciidoc30
-rw-r--r--docs/en/cowboy/2.2/guide/resp/index.html28
2 files changed, 57 insertions, 1 deletions
diff --git a/docs/en/cowboy/2.2/guide/resp.asciidoc b/docs/en/cowboy/2.2/guide/resp.asciidoc
index 6d4967e0..781157d6 100644
--- a/docs/en/cowboy/2.2/guide/resp.asciidoc
+++ b/docs/en/cowboy/2.2/guide/resp.asciidoc
@@ -128,7 +128,35 @@ in advance. This will ensure that the best response method
is selected and help clients understand when the response
is fully received.
-// @todo Document trailers here.
+Cowboy also provides a function to send response trailers.
+Response trailers are semantically equivalent to the headers
+you send in the response, only they are sent at the end.
+This is especially useful to attach information to the
+response that could not be generated until the response
+body was fully generated.
+
+Trailer fields must be listed in the trailer header. Any
+field not listed might be dropped by the client or an intermediary.
+
+[source,erlang]
+----
+Req = cowboy_req:stream_reply(200, #{
+ <<"content-type">> => <<"text/html">>,
+ <<"trailer">> => <<"expires, content-md5">>
+}, Req0),
+
+cowboy_req:stream_body("<html><head>Hello world!</head>", nofin, Req),
+cowboy_req:stream_body("<body><p>Hats off!</p></body></html>", nofin, Req),
+
+cowboy_req:stream_trailers(#{
+ <<"expires">> => <<"Sun, 10 Dec 2017 19:13:47 GMT">>,
+ <<"content-md5">> => <<"c6081d20ff41a42ce17048ed1c0345e2">>
+}, Req).
+----
+
+The stream ends with trailers. It is no longer possible to
+send data after sending trailers. You cannot send trailers
+after setting the `fin` flag when streaming the body.
=== Preset response headers
diff --git a/docs/en/cowboy/2.2/guide/resp/index.html b/docs/en/cowboy/2.2/guide/resp/index.html
index 0b18cc4c..eec9c9ff 100644
--- a/docs/en/cowboy/2.2/guide/resp/index.html
+++ b/docs/en/cowboy/2.2/guide/resp/index.html
@@ -186,6 +186,34 @@ set the content-length header in the response if you know it
in advance. This will ensure that the best response method
is selected and help clients understand when the response
is fully received.</p></div>
+<div class="paragraph"><p>Cowboy also provides a function to send response trailers.
+Response trailers are semantically equivalent to the headers
+you send in the response, only they are sent at the end.
+This is especially useful to attach information to the
+response that could not be generated until the response
+body was fully generated.</p></div>
+<div class="paragraph"><p>Trailer fields must be listed in the trailer header. Any
+field not listed might be dropped by the client or an intermediary.</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">Req</span> <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">cowboy_req:stream_reply</span></span>(<span style="color: #993399">200</span>, #{
+ <span style="color: #990000">&lt;&lt;</span><span style="color: #FF0000">"content-type"</span><span style="color: #990000">&gt;&gt;</span> <span style="color: #990000">=&gt;</span> <span style="color: #990000">&lt;&lt;</span><span style="color: #FF0000">"text/html"</span><span style="color: #990000">&gt;&gt;</span>,
+ <span style="color: #990000">&lt;&lt;</span><span style="color: #FF0000">"trailer"</span><span style="color: #990000">&gt;&gt;</span> <span style="color: #990000">=&gt;</span> <span style="color: #990000">&lt;&lt;</span><span style="color: #FF0000">"expires, content-md5"</span><span style="color: #990000">&gt;&gt;</span>
+}, <span style="color: #009900">Req0</span>),
+
+<span style="font-weight: bold"><span style="color: #000000">cowboy_req:stream_body</span></span>(<span style="color: #FF0000">"&lt;html&gt;&lt;head&gt;Hello world!&lt;/head&gt;"</span>, <span style="color: #FF6600">nofin</span>, <span style="color: #009900">Req</span>),
+<span style="font-weight: bold"><span style="color: #000000">cowboy_req:stream_body</span></span>(<span style="color: #FF0000">"&lt;body&gt;&lt;p&gt;Hats off!&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;"</span>, <span style="color: #FF6600">nofin</span>, <span style="color: #009900">Req</span>),
+
+<span style="font-weight: bold"><span style="color: #000000">cowboy_req:stream_trailers</span></span>(#{
+ <span style="color: #990000">&lt;&lt;</span><span style="color: #FF0000">"expires"</span><span style="color: #990000">&gt;&gt;</span> <span style="color: #990000">=&gt;</span> <span style="color: #990000">&lt;&lt;</span><span style="color: #FF0000">"Sun, 10 Dec 2017 19:13:47 GMT"</span><span style="color: #990000">&gt;&gt;</span>,
+ <span style="color: #990000">&lt;&lt;</span><span style="color: #FF0000">"content-md5"</span><span style="color: #990000">&gt;&gt;</span> <span style="color: #990000">=&gt;</span> <span style="color: #990000">&lt;&lt;</span><span style="color: #FF0000">"c6081d20ff41a42ce17048ed1c0345e2"</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>The stream ends with trailers. It is no longer possible to
+send data after sending trailers. You cannot send trailers
+after setting the <code>fin</code> flag when streaming the body.</p></div>
</div>
</div>
<div class="sect1">