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/loop_handlers/index.html | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'docs/en/cowboy/2.0/guide/loop_handlers/index.html') 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 -- cgit v1.2.3