From fdc955ab18ba2fe285c75b75a8b92cf9f9436adc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Mon, 2 Jan 2017 19:56:53 +0100 Subject: Update docs --- docs/en/cowboy/2.0/guide/architecture/index.html | 4 +- docs/en/cowboy/2.0/guide/broken_clients/index.html | 4 +- docs/en/cowboy/2.0/guide/flow_diagram.asciidoc | 8 + docs/en/cowboy/2.0/guide/flow_diagram/index.html | 15 ++ docs/en/cowboy/2.0/guide/handlers.asciidoc | 9 +- docs/en/cowboy/2.0/guide/handlers/index.html | 9 +- docs/en/cowboy/2.0/guide/hooks/index.html | 8 +- docs/en/cowboy/2.0/guide/index.html | 46 ++++-- docs/en/cowboy/2.0/guide/introduction.asciidoc | 2 +- docs/en/cowboy/2.0/guide/introduction/index.html | 2 +- docs/en/cowboy/2.0/guide/listeners.asciidoc | 2 +- docs/en/cowboy/2.0/guide/listeners/index.html | 2 +- docs/en/cowboy/2.0/guide/loop_handlers.asciidoc | 15 +- docs/en/cowboy/2.0/guide/loop_handlers/index.html | 14 +- docs/en/cowboy/2.0/guide/middlewares/index.html | 4 +- docs/en/cowboy/2.0/guide/multipart.asciidoc | 2 +- docs/en/cowboy/2.0/guide/multipart/index.html | 2 +- docs/en/cowboy/2.0/guide/overview/index.html | 15 ++ docs/en/cowboy/2.0/guide/rest_handlers.asciidoc | 8 +- docs/en/cowboy/2.0/guide/rest_handlers/index.html | 8 +- docs/en/cowboy/2.0/guide/streams.asciidoc | 15 ++ docs/en/cowboy/2.0/guide/streams/index.html | 182 +++++++++++++++++++++ docs/en/cowboy/2.0/guide/sub_protocols/index.html | 4 +- docs/en/cowboy/2.0/guide/ws_handlers/index.html | 4 +- 24 files changed, 321 insertions(+), 63 deletions(-) create mode 100644 docs/en/cowboy/2.0/guide/streams.asciidoc create mode 100644 docs/en/cowboy/2.0/guide/streams/index.html (limited to 'docs/en') diff --git a/docs/en/cowboy/2.0/guide/architecture/index.html b/docs/en/cowboy/2.0/guide/architecture/index.html index 67a10e88..552fa92c 100644 --- a/docs/en/cowboy/2.0/guide/architecture/index.html +++ b/docs/en/cowboy/2.0/guide/architecture/index.html @@ -127,8 +127,8 @@ only processing short-lived requests.

diff --git a/docs/en/cowboy/2.0/guide/flow_diagram.asciidoc b/docs/en/cowboy/2.0/guide/flow_diagram.asciidoc index 10954040..ad2110dc 100644 --- a/docs/en/cowboy/2.0/guide/flow_diagram.asciidoc +++ b/docs/en/cowboy/2.0/guide/flow_diagram.asciidoc @@ -2,3 +2,11 @@ == Flow diagram Placeholder chapter. + +Cowboy 2.0 has changed the request flow and general architecture. +You can read about the Cowboy 1.0 architecture and flow here: + +* xref:architecture[Architecture] +* xref:overview[Overview] + +This chapter will be updated in a future pre-release. 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 25f2b799..191aa3bd 100644 --- a/docs/en/cowboy/2.0/guide/flow_diagram/index.html +++ b/docs/en/cowboy/2.0/guide/flow_diagram/index.html @@ -70,6 +70,21 @@

Flow diagram

Placeholder chapter.

+

Cowboy 2.0 has changed the request flow and general architecture. +You can read about the Cowboy 1.0 architecture and flow here:

+
+

This chapter will be updated in a future pre-release.

diff --git a/docs/en/cowboy/2.0/guide/handlers.asciidoc b/docs/en/cowboy/2.0/guide/handlers.asciidoc index 88fbc21f..e073dfb6 100644 --- a/docs/en/cowboy/2.0/guide/handlers.asciidoc +++ b/docs/en/cowboy/2.0/guide/handlers.asciidoc @@ -29,9 +29,9 @@ We need to use the Req object to reply. [source,erlang] ---- init(Req0, State) -> - Req = cowboy_req:reply(200, [ - {<<"content-type">>, <<"text/plain">>} - ], <<"Hello World!">>, Req0), + Req = cowboy_req:reply(200, #{ + <<"content-type">> => <<"text/plain">> + }, <<"Hello World!">>, Req0), {ok, Req, State}. ---- @@ -81,8 +81,7 @@ xref:sub_protocols[Sub protocols] chapter. === Cleaning up -With the exception of Websocket handlers, all handler types -provide the optional `terminate/3` callback. +All handler types provide the optional `terminate/3` callback. [source,erlang] ---- diff --git a/docs/en/cowboy/2.0/guide/handlers/index.html b/docs/en/cowboy/2.0/guide/handlers/index.html index a9d21a16..f1b3649d 100644 --- a/docs/en/cowboy/2.0/guide/handlers/index.html +++ b/docs/en/cowboy/2.0/guide/handlers/index.html @@ -96,9 +96,9 @@ by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite -->
init(Req0, State) ->
-    Req = cowboy_req:reply(200, [
-        {<<"content-type">>, <<"text/plain">>}
-    ], <<"Hello World!">>, Req0),
+    Req = cowboy_req:reply(200, #{
+        <<"content-type">> => <<"text/plain">>
+    }, <<"Hello World!">>, Req0),
     {ok, Req, State}.

Cowboy will immediately send a response when cowboy:reply/4 is called.

@@ -146,8 +146,7 @@ http://www.gnu.org/software/src-highlite -->

Cleaning up

-

With the exception of Websocket handlers, all handler types -provide the optional terminate/3 callback.

+

All handler types provide the optional terminate/3 callback.

diff --git a/docs/en/cowboy/2.0/guide/index.html b/docs/en/cowboy/2.0/guide/index.html index d07f9ba6..7f0eb137 100644 --- a/docs/en/cowboy/2.0/guide/index.html +++ b/docs/en/cowboy/2.0/guide/index.html @@ -100,8 +100,6 @@ Getting started

-
-
+
+

Deprecated chapters

+
+
+
+
+

About the deprecated chapters

+
+

The following chapters were relevant in Cowboy 1.0. They have +not been updated for Cowboy 2.0 yet. The information in these +chapters may or may not be useful.

+ -
diff --git a/docs/en/cowboy/2.0/guide/introduction.asciidoc b/docs/en/cowboy/2.0/guide/introduction.asciidoc index c9d042d3..1f9b52e4 100644 --- a/docs/en/cowboy/2.0/guide/introduction.asciidoc +++ b/docs/en/cowboy/2.0/guide/introduction.asciidoc @@ -42,7 +42,7 @@ Cowboy is developed for Erlang/OTP 19.0 and newer. Cowboy uses the ISC License. ---- -Copyright (c) 2011-2016, Loïc Hoguin +Copyright (c) 2011-2017, Loïc Hoguin Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above diff --git a/docs/en/cowboy/2.0/guide/introduction/index.html b/docs/en/cowboy/2.0/guide/introduction/index.html index 5ab7823f..8e63cf1c 100644 --- a/docs/en/cowboy/2.0/guide/introduction/index.html +++ b/docs/en/cowboy/2.0/guide/introduction/index.html @@ -107,7 +107,7 @@ on other platforms.

Cowboy uses the ISC License.

-
Copyright (c) 2011-2016, Loïc Hoguin <essen@ninenines.eu>
+
Copyright (c) 2011-2017, Loïc Hoguin <essen@ninenines.eu>
 
 Permission to use, copy, modify, and/or distribute this software for any
 purpose with or without fee is hereby granted, provided that the above
diff --git a/docs/en/cowboy/2.0/guide/listeners.asciidoc b/docs/en/cowboy/2.0/guide/listeners.asciidoc
index 901b9220..7d5faec0 100644
--- a/docs/en/cowboy/2.0/guide/listeners.asciidoc
+++ b/docs/en/cowboy/2.0/guide/listeners.asciidoc
@@ -7,7 +7,7 @@ Depending on the connection handshake, one or another protocol
 may be used.
 
 This chapter is specific to Cowboy. Please refer to the
-http://ninenines.eu/docs/en/ranch/1.2/guide/listeners/[Ranch User Guide]
+http://ninenines.eu/docs/en/ranch/1.3/guide/listeners/[Ranch User Guide]
 for more information about listeners.
 
 Cowboy provides two types of listeners: one listening for
diff --git a/docs/en/cowboy/2.0/guide/listeners/index.html b/docs/en/cowboy/2.0/guide/listeners/index.html
index 8dc05c30..d4209d48 100644
--- a/docs/en/cowboy/2.0/guide/listeners/index.html
+++ b/docs/en/cowboy/2.0/guide/listeners/index.html
@@ -74,7 +74,7 @@ new connections. Incoming connections get handled by Cowboy.
 Depending on the connection handshake, one or another protocol
 may be used.

This chapter is specific to Cowboy. Please refer to the -Ranch User Guide +Ranch User Guide for more information about listeners.

Cowboy provides two types of listeners: one listening for clear TCP connections, and one listening for secure TLS diff --git a/docs/en/cowboy/2.0/guide/loop_handlers.asciidoc b/docs/en/cowboy/2.0/guide/loop_handlers.asciidoc index c0195ea0..2c82c530 100644 --- a/docs/en/cowboy/2.0/guide/loop_handlers.asciidoc +++ b/docs/en/cowboy/2.0/guide/loop_handlers.asciidoc @@ -16,7 +16,7 @@ most known example of such practice is known as long polling. Loop handlers can also be used for requests where a response is partially available and you need to stream the response body while the connection is open. The most known example of such -practice is known as server-sent events. +practice is server-sent events. While the same can be accomplished using plain HTTP handlers, it is recommended to use loop handlers because they are well-tested @@ -66,7 +66,7 @@ message otherwise. [source,erlang] ---- info({reply, Body}, Req, State) -> - cowboy_req:reply(200, [], Body, Req), + cowboy_req:reply(200, #{}, Body, Req), {stop, Req, State}; info(_Msg, Req, State) -> {ok, Req, State, hibernate}. @@ -96,19 +96,19 @@ This can be done by initiating a chunked reply in the every time a message is received. The following snippet does exactly that. As you can see -a chunk is sent every time a `chunk` message is received, +a chunk is sent every time an `event` message is received, and the loop is stopped by sending an `eof` message. [source,erlang] ---- init(Req, State) -> - Req2 = cowboy_req:chunked_reply(200, [], Req), + Req2 = cowboy_req:stream_reply(200, Req), {cowboy_loop, Req2, State}. info(eof, Req, State) -> {stop, Req, State}; -info({chunk, Chunk}, Req, State) -> - cowboy_req:chunk(Chunk, Req), +info({event, Data}, Req, State) -> + cowboy_req:stream_body(Data, nofin, Req), {ok, Req, State}; info(_Msg, Req, State) -> {ok, Req, State}. @@ -125,6 +125,9 @@ for general instructions about cleaning up. === Timeout +Note that this feature currently does not work. It will be +brought back in a future 2.0 pre-release. + By default Cowboy will not attempt to close the connection if there is no activity from the client. This is not always desirable, which is why you can set a timeout. Cowboy will diff --git a/docs/en/cowboy/2.0/guide/loop_handlers/index.html b/docs/en/cowboy/2.0/guide/loop_handlers/index.html index 64dc4b31..aec5721e 100644 --- a/docs/en/cowboy/2.0/guide/loop_handlers/index.html +++ b/docs/en/cowboy/2.0/guide/loop_handlers/index.html @@ -80,7 +80,7 @@ most known example of such practice is known as long polling.

Loop handlers can also be used for requests where a response is partially available and you need to stream the response body while the connection is open. The most known example of such -practice is known as server-sent events.

+practice is server-sent events.

While the same can be accomplished using plain HTTP handlers, it is recommended to use loop handlers because they are well-tested and allow using built-in features like hibernation and timeouts.

@@ -131,7 +131,7 @@ by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite -->
info({reply, Body}, Req, State) ->
-    cowboy_req:reply(200, [], Body, Req),
+    cowboy_req:reply(200, #{}, Body, Req),
     {stop, Req, State};
 info(_Msg, Req, State) ->
     {ok, Req, State, hibernate}.
@@ -156,7 +156,7 @@ This can be done by initiating a chunked reply in the init/2 callback and then using cowboy_req:chunk/2 every time a message is received.

The following snippet does exactly that. As you can see -a chunk is sent every time a chunk message is received, +a chunk is sent every time an event message is received, and the loop is stopped by sending an eof message.

init(Req, State) ->
-    Req2 = cowboy_req:chunked_reply(200, [], Req),
+    Req2 = cowboy_req:stream_reply(200, Req),
     {cowboy_loop, Req2, State}.
 
 info(eof, Req, State) ->
     {stop, Req, State};
-info({chunk, Chunk}, Req, State) ->
-    cowboy_req:chunk(Chunk, Req),
+info({event, Data}, Req, State) ->
+    cowboy_req:stream_body(Data, nofin, Req),
     {ok, Req, State};
 info(_Msg, Req, State) ->
     {ok, Req, State}.
@@ -187,6 +187,8 @@ for general instructions about cleaning up.

Timeout

+

Note that this feature currently does not work. It will be +brought back in a future 2.0 pre-release.

By default Cowboy will not attempt to close the connection if there is no activity from the client. This is not always desirable, which is why you can set a timeout. Cowboy will diff --git a/docs/en/cowboy/2.0/guide/middlewares/index.html b/docs/en/cowboy/2.0/guide/middlewares/index.html index 53a751d1..8b74b9a5 100644 --- a/docs/en/cowboy/2.0/guide/middlewares/index.html +++ b/docs/en/cowboy/2.0/guide/middlewares/index.html @@ -164,8 +164,8 @@ values. It puts the result of the request handling into result.

+ + + + + + +
diff --git a/docs/en/cowboy/2.0/guide/rest_handlers.asciidoc b/docs/en/cowboy/2.0/guide/rest_handlers.asciidoc index 748fca49..c69f02b2 100644 --- a/docs/en/cowboy/2.0/guide/rest_handlers.asciidoc +++ b/docs/en/cowboy/2.0/guide/rest_handlers.asciidoc @@ -101,13 +101,13 @@ and in the second case that we send one as HTML. === Meta data -Cowboy will set informative meta values at various points of the -execution. You can retrieve them using `cowboy_req:meta/{2,3}`. -The values are defined in the following table. +Cowboy will set informative values to the Req object at various +points of the execution. You can retrieve them by matching the +Req object directly. The values are defined in the following table: [cols="<,<",options="header"] |=== -| Meta key | Details +| Key | Details | media_type | The content-type negotiated for the response entity. | language | The language negotiated for the response entity. | charset | The charset negotiated for the response entity. diff --git a/docs/en/cowboy/2.0/guide/rest_handlers/index.html b/docs/en/cowboy/2.0/guide/rest_handlers/index.html index a0691398..5e7f84aa 100644 --- a/docs/en/cowboy/2.0/guide/rest_handlers/index.html +++ b/docs/en/cowboy/2.0/guide/rest_handlers/index.html @@ -258,9 +258,9 @@ and in the second case that we send one as HTML.

Meta data

-

Cowboy will set informative meta values at various points of the -execution. You can retrieve them using cowboy_req:meta/{2,3}. -The values are defined in the following table.

+

Cowboy will set informative values to the Req object at various +points of the execution. You can retrieve them by matching the +Req object directly. The values are defined in the following table:

- + diff --git a/docs/en/cowboy/2.0/guide/streams.asciidoc b/docs/en/cowboy/2.0/guide/streams.asciidoc new file mode 100644 index 00000000..243e5815 --- /dev/null +++ b/docs/en/cowboy/2.0/guide/streams.asciidoc @@ -0,0 +1,15 @@ +[[streams]] +== Streams + +Placeholder chapter. + +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. + +Streams are meant to replace hooks. The relevant chapters +for Cowboy 1.0 were: + +* xref:hooks[Hooks] +* xref:broken_clients[Dealing with broken clients] diff --git a/docs/en/cowboy/2.0/guide/streams/index.html b/docs/en/cowboy/2.0/guide/streams/index.html new file mode 100644 index 00000000..ddaad48e --- /dev/null +++ b/docs/en/cowboy/2.0/guide/streams/index.html @@ -0,0 +1,182 @@ + + + + + + + + + + + + Nine Nines: Streams + + + + + + + + + + + + + + + + + + +
+
+
+
+ +

Streams

+ +

Placeholder chapter.

+

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.

+

Streams are meant to replace hooks. The relevant chapters +for Cowboy 1.0 were:

+
+ + + + + + + + + + + + +
+ +
+ + +

+ Cowboy + 2.0 + + User Guide +

+ + + +

Navigation

+ +

Version select

+ + +
+
+
+
+ + + + + + + + + + + + diff --git a/docs/en/cowboy/2.0/guide/sub_protocols/index.html b/docs/en/cowboy/2.0/guide/sub_protocols/index.html index 6293bc08..29d8f3ea 100644 --- a/docs/en/cowboy/2.0/guide/sub_protocols/index.html +++ b/docs/en/cowboy/2.0/guide/sub_protocols/index.html @@ -148,8 +148,8 @@ the optional terminate/3 callback is called, if present.

- - Hooks + + Architecture diff --git a/docs/en/cowboy/2.0/guide/ws_handlers/index.html b/docs/en/cowboy/2.0/guide/ws_handlers/index.html index 5e484272..c3141194 100644 --- a/docs/en/cowboy/2.0/guide/ws_handlers/index.html +++ b/docs/en/cowboy/2.0/guide/ws_handlers/index.html @@ -347,8 +347,8 @@ close frame will not be sent.

- - Architecture + + Streams -- cgit v1.2.3
Meta key Key Details