path: root/include
diff options
authorLoïc Hoguin <[email protected]>2012-05-01 01:59:36 +0200
committerLoïc Hoguin <[email protected]>2012-05-04 06:24:10 +0200
commit57fda142175a7fd0340d9030e0477c16e13dc5f5 (patch)
treea83701cdedf0a21b814fd3e78538d2473926e446 /include
parent7ed93fcc8f3fe42cbe22e96e3352b444c2480f74 (diff)
Add an 'onresponse' hook
This new protocol option is a fun. It expects 3 args: the Status code used in the reply (this is the cowboy_http:status() type, it can be an integer or a binary), the headers that will be sent in the reply, and the Req. It should only return a possibly modified Req. This can be used for many things like error logging or custom error pages. If a reply is sent inside the hook, then Cowboy will discard the reply initially sent. Extra caution must be used in the handlers making use of inline chunked replies as they will throw an error. This fun cannot be used as a filter, you can either observe the reply sent or discard it to send a different one instead. The hook will not be called for replies sent from inside the hook.
Diffstat (limited to 'include')
1 files changed, 2 insertions, 0 deletions
diff --git a/include/http.hrl b/include/http.hrl
index 21d837b..dc849c2 100644
--- a/include/http.hrl
+++ b/include/http.hrl
@@ -52,5 +52,7 @@
fun(() -> {sent, non_neg_integer()})},
%% Functions.
+ onresponse = undefined :: undefined | fun((cowboy_http:status(),
+ cowboy_http:headers(), #http_req{}) -> #http_req{}),
urldecode :: {fun((binary(), T) -> binary()), T}