From 1bb95a639cc90500014c4783db4416c2898e5166 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Sun, 23 Jul 2017 19:59:12 +0200 Subject: Update the Cowboy 2.0 docs --- docs/en/cowboy/2.0/guide/hooks/index.html | 201 ------------------------------ 1 file changed, 201 deletions(-) delete mode 100644 docs/en/cowboy/2.0/guide/hooks/index.html (limited to 'docs/en/cowboy/2.0/guide/hooks/index.html') diff --git a/docs/en/cowboy/2.0/guide/hooks/index.html b/docs/en/cowboy/2.0/guide/hooks/index.html deleted file mode 100644 index dd42215e..00000000 --- a/docs/en/cowboy/2.0/guide/hooks/index.html +++ /dev/null @@ -1,201 +0,0 @@ - - - - - - - - - - - - Nine Nines: Hooks - - - - - - - - - - - - - - - - -
-
-
-
- -

Hooks

- -

Hooks allow the user to customize Cowboy’s behavior during specific -operations.

-
-

Onresponse

-
-

The onresponse hook is called right before sending the response -to the socket. It can be used for the purposes of logging responses, -or for modifying the response headers or body. The best example is -providing custom error pages.

-

Note that this function MUST NOT crash. Cowboy may or may not send a -reply if this function crashes. If a reply is sent, the hook MUST -explicitly provide all headers that are needed.

-

You can specify the onresponse hook when creating the listener.

-
-
-
cowboy:start_http(my_http_listener, 100,
-    [{port, 8080}],
-    [
-        {env, [{dispatch, Dispatch}]},
-        {onresponse, fun ?MODULE:custom_404_hook/4}
-    ]
-).
-

The following hook function will provide a custom body for 404 errors -when it has not been provided before, and will let Cowboy proceed with -the default response otherwise.

-
-
-
custom_404_hook(404, Headers, <<>>, Req) ->
-    Body = <<"404 Not Found.">>,
-    Headers2 = lists:keyreplace(<<"content-length">>, 1, Headers,
-        {<<"content-length">>, integer_to_list(byte_size(Body))}),
-    cowboy_req:reply(404, Headers2, Body, Req);
-custom_404_hook(_, _, _, Req) ->
-    Req.
-

Again, make sure to always return the last request object obtained.

-
-
- - - - - - - - - - - - -
- -
- - -

- Cowboy - 2.0 - - User Guide -

- - - -

Navigation

- -

Version select

- - -
-
-
-
- - - - - - - - - -- cgit v1.2.3