From 57fda142175a7fd0340d9030e0477c16e13dc5f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Tue, 1 May 2012 01:59:36 +0200 Subject: 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. --- include/http.hrl | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include') 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} }). -- cgit v1.2.3