summaryrefslogtreecommitdiffstats
path: root/docs/en/cowboy/2.0/guide/loop_handlers.asciidoc
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2017-01-02 19:56:53 +0100
committerLoïc Hoguin <[email protected]>2017-01-02 19:56:53 +0100
commitfdc955ab18ba2fe285c75b75a8b92cf9f9436adc (patch)
treee038f2df840c2583e374cee21e240c3082f25186 /docs/en/cowboy/2.0/guide/loop_handlers.asciidoc
parent1780abb415b1a9c27c3a1f53267e9689da6b0005 (diff)
downloadninenines.eu-fdc955ab18ba2fe285c75b75a8b92cf9f9436adc.tar.gz
ninenines.eu-fdc955ab18ba2fe285c75b75a8b92cf9f9436adc.tar.bz2
ninenines.eu-fdc955ab18ba2fe285c75b75a8b92cf9f9436adc.zip
Update docs
Diffstat (limited to 'docs/en/cowboy/2.0/guide/loop_handlers.asciidoc')
-rw-r--r--docs/en/cowboy/2.0/guide/loop_handlers.asciidoc15
1 files changed, 9 insertions, 6 deletions
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