aboutsummaryrefslogtreecommitdiffstats
path: root/doc/src/guide/handlers.asciidoc
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2016-05-24 14:50:27 +0200
committerLoïc Hoguin <[email protected]>2016-05-24 14:50:27 +0200
commitb5a40256ddd5585d12c2a01771eb93d4a8630a62 (patch)
tree9d03e630d501852b216a8b7990a1d03a02e9f4dd /doc/src/guide/handlers.asciidoc
parent25912dfc05e45e0f4453f689410fce80a1af69ab (diff)
downloadcowboy-b5a40256ddd5585d12c2a01771eb93d4a8630a62.tar.gz
cowboy-b5a40256ddd5585d12c2a01771eb93d4a8630a62.tar.bz2
cowboy-b5a40256ddd5585d12c2a01771eb93d4a8630a62.zip
Partial update of the user guide
I will do more breaking changes before documenting more.
Diffstat (limited to 'doc/src/guide/handlers.asciidoc')
-rw-r--r--doc/src/guide/handlers.asciidoc24
1 files changed, 9 insertions, 15 deletions
diff --git a/doc/src/guide/handlers.asciidoc b/doc/src/guide/handlers.asciidoc
index b6cefdd..83ae2ff 100644
--- a/doc/src/guide/handlers.asciidoc
+++ b/doc/src/guide/handlers.asciidoc
@@ -28,18 +28,16 @@ We need to use the Req object for sending a reply.
[source,erlang]
----
-init(Req, _Opts) ->
- Req2 = cowboy_req:reply(200, [
+init(Req, State) ->
+ cowboy_req:reply(200, [
{<<"content-type">>, <<"text/plain">>}
], <<"Hello World!">>, Req),
- {ok, Req2, #state{}}.
+ {ok, Req, State}.
----
As you can see we return a 3-tuple. `ok` means that the
-handler ran successfully. The Req object is returned as
-it may have been modified as is the case here: replying
-returns a modified Req object that you need to return
-back to Cowboy for proper operations.
+handler ran successfully. Note that Cowboy will immediately
+send a response when `cowboy:reply/4` is called.
The last value of the tuple is a state that will be used
in every subsequent callbacks to this handler. Plain HTTP
@@ -94,12 +92,8 @@ This callback is strictly reserved for any required cleanup.
You cannot send a response from this function. There is no
other return value.
-If you used the process dictionary, timers, monitors or may
-be receiving messages, then you can use this function to clean
-them up, as Cowboy might reuse the process for the next
-keep-alive request.
+This callback is optional because it is rarely necessary.
+Cleanup should be done in separate processes directly (by
+monitoring the handler process to detect when it exits).
-Note that while this function may be called in a Websocket
-handler, it is generally not useful to do any clean up as
-the process terminates immediately after calling this callback
-when using Websocket.
+Cowboy does not reuse processes for different requests.