From 92b54aacc0de5446dd5497c39897b0bbff72e626 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Wed, 13 Jun 2018 09:54:12 +0200 Subject: Rebuild using Asciideck --- .../en/cowboy/2.4/manual/cowboy_handler/index.html | 108 ++++++--------------- 1 file changed, 29 insertions(+), 79 deletions(-) (limited to 'docs/en/cowboy/2.4/manual/cowboy_handler/index.html') diff --git a/docs/en/cowboy/2.4/manual/cowboy_handler/index.html b/docs/en/cowboy/2.4/manual/cowboy_handler/index.html index 5414b066..e6a0c3f4 100644 --- a/docs/en/cowboy/2.4/manual/cowboy_handler/index.html +++ b/docs/en/cowboy/2.4/manual/cowboy_handler/index.html @@ -62,96 +62,46 @@

cowboy_handler(3)

-

Name

-
-

cowboy_handler - Plain HTTP handlers

-
-
-
+

cowboy_handler - Plain HTTP handlers

Description

-
-

The cowboy_handler middleware executes the handler selected -by the router or any other preceding middleware.

-

This middleware takes the handler module and initial state -from the handler and handler_opts environment values, -respectively. On completion, it adds a result value to -the middleware environment, containing the return value -of the terminate/3 callback (if defined) and ok otherwise.

-

This module also defines a callback interface for handling -HTTP requests.

-
-
-
+

The cowboy_handler middleware executes the handler selected by the router or any other preceding middleware.

+

This middleware takes the handler module and initial state from the handler and handler_opts environment values, respectively. On completion, it adds a result value to the middleware environment, containing the return value of the terminate/3 callback (if defined) and ok otherwise.

+

This module also defines a callback interface for handling HTTP requests.

Callbacks

-
-

Plain HTTP handlers implement the following interface:

-
-
-
init(Req, State) -> {ok, Req, State}
-
-terminate(Reason, Req, State) -> ok  %% optional
-
-Req    :: cowboy_req:req()
-State  :: any()
-Reason :: normal
-        | {crash, error | exit | throw, any()}
-

These two callbacks are common to all handlers.

-

Plain HTTP handlers do all their work in the init/2 -callback. Returning ok terminates the handler. If no -response is sent, Cowboy will send a 204 No Content.

-

The optional terminate/3 callback will ultimately be called -with the reason for the termination of the handler. -Cowboy will terminate the process right after this. There -is no need to perform any cleanup in this callback.

-

The following terminate reasons are defined for plain HTTP -handlers:

-
-
-normal -
-
-

- The connection was closed normally. -

+
init(Req, State) -> {ok, Req, State}
+
+terminate(Reason, Req, State) -> ok  %% optional
+
+Req    :: cowboy_req:req()
+State  :: any()
+Reason :: normal
+        | {crash, error | exit | throw, any()}
+
+

These two callbacks are common to all handlers.

+

Plain HTTP handlers do all their work in the init/2 callback. Returning ok terminates the handler. If no response is sent, Cowboy will send a 204 No Content.

+

The optional terminate/3 callback will ultimately be called with the reason for the termination of the handler. Cowboy will terminate the process right after this. There is no need to perform any cleanup in this callback.

+

The following terminate reasons are defined for plain HTTP handlers:

+
normal
+

The connection was closed normally.

-
-{crash, Class, Reason} -
-
-

- A crash occurred in the handler. Class and Reason can be - used to obtain more information about the crash. The function - erlang:get_stacktrace/0 can also be called to obtain the - stacktrace of the process when the crash occurred. -

+
{crash, Class, Reason}
+

A crash occurred in the handler. Class and Reason can be used to obtain more information about the crash. The function erlang:get_stacktrace/0 can also be called to obtain the stacktrace of the process when the crash occurred.

-
- - -
+

Exports

-
-

The following function should be called by modules implementing -custom handlers to execute the optional terminate callback:

-
-
-
-
+

See also

- -
+

cowboy(7)

+ -- cgit v1.2.3