diff options
author | Loïc Hoguin <[email protected]> | 2013-03-02 02:59:26 +0100 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2013-03-02 02:59:26 +0100 |
commit | 3a907d175fa740a7cd328fe3bcbf2924174b0e8e (patch) | |
tree | b8c1aff6602bee191f252ed74c959b0b077b6811 /guide | |
parent | 23b3b038e930646af7f27a439e9dca1cf0c0e453 (diff) | |
parent | 88414e36b4199f10ed5b29d5fffda037c5d81eca (diff) | |
download | cowboy-3a907d175fa740a7cd328fe3bcbf2924174b0e8e.tar.gz cowboy-3a907d175fa740a7cd328fe3bcbf2924174b0e8e.tar.bz2 cowboy-3a907d175fa740a7cd328fe3bcbf2924174b0e8e.zip |
Merge branch 'onresponse_example' of git://github.com/acammack/cowboy
Diffstat (limited to 'guide')
-rw-r--r-- | guide/hooks.md | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/guide/hooks.md b/guide/hooks.md index d4b520a..d7e6c72 100644 --- a/guide/hooks.md +++ b/guide/hooks.md @@ -48,7 +48,8 @@ or for modifying the response headers or body. The best example is providing custom error pages. Note that like the `onrequest` hook, this function MUST NOT crash. -Cowboy may or may not send a reply if this function crashes. +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 also. @@ -68,7 +69,10 @@ the default response otherwise. ``` erlang custom_404_hook(404, Headers, <<>>, Req) -> - {ok, Req2} = cowboy_req:reply(404, Headers, <<"404 Not Found.">>, Req), + Body = <<"404 Not Found.">>, + Headers2 = lists:keyreplace(<<"content-length">>, 1, Headers, + {<<"content-length">>, integer_to_list(byte_size(Body))}), + {ok, Req2} = cowboy_req:reply(404, Headers2, Body, Req), Req2; custom_404_hook(_, _, _, Req) -> Req. |