aboutsummaryrefslogtreecommitdiffstats
path: root/doc/src/guide/loop_handlers.asciidoc
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2017-01-02 14:20:15 +0100
committerLoïc Hoguin <[email protected]>2017-01-02 14:46:19 +0100
commit271e31c629be2dff93d68e01c9a8a9c5c34b7e2c (patch)
treeb20ba4f01a174479c1cde0d7abb610dbfa757d05 /doc/src/guide/loop_handlers.asciidoc
parent5838a0c81a978377084b33fd086de10f9775f425 (diff)
downloadcowboy-271e31c629be2dff93d68e01c9a8a9c5c34b7e2c.tar.gz
cowboy-271e31c629be2dff93d68e01c9a8a9c5c34b7e2c.tar.bz2
cowboy-271e31c629be2dff93d68e01c9a8a9c5c34b7e2c.zip
Various fixes and tweaks to the user guide
Diffstat (limited to 'doc/src/guide/loop_handlers.asciidoc')
-rw-r--r--doc/src/guide/loop_handlers.asciidoc15
1 files changed, 9 insertions, 6 deletions
diff --git a/doc/src/guide/loop_handlers.asciidoc b/doc/src/guide/loop_handlers.asciidoc
index c0195ea..2c82c53 100644
--- a/doc/src/guide/loop_handlers.asciidoc
+++ b/doc/src/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