From 76cd1e40c933e60ed507474cceea4e25e10db225 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Thu, 4 Oct 2012 22:59:33 +0200 Subject: The onresponse hook now receives 4 arguments, including the body We do not always provide the body however. It is not available when using chunked replies, or when using set_resp_body_fun. --- src/cowboy_protocol.erl | 4 ++-- src/cowboy_req.erl | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/cowboy_protocol.erl b/src/cowboy_protocol.erl index bf81e52..c5ea561 100644 --- a/src/cowboy_protocol.erl +++ b/src/cowboy_protocol.erl @@ -34,7 +34,7 @@ %% any dispatching is done. Host info, path info and bindings are thus %% not available at this point. %%
onresponse
Optional fun that allows replacing a response -%% sent by the application based on its status code or headers.
+%% sent by the application. %%
timeout
Time in milliseconds before an idle %% connection is closed. Defaults to 5000 milliseconds.
%% @@ -56,7 +56,7 @@ -type onrequest_fun() :: fun((Req) -> Req). -type onresponse_fun() :: - fun((cowboy_http:status(), cowboy_http:headers(), Req) -> Req). + fun((cowboy_http:status(), cowboy_http:headers(), iodata(), Req) -> Req). -export_type([onrequest_fun/0]). -export_type([onresponse_fun/0]). diff --git a/src/cowboy_req.erl b/src/cowboy_req.erl index 14eb88d..5b8cb7e 100644 --- a/src/cowboy_req.erl +++ b/src/cowboy_req.erl @@ -1108,7 +1108,7 @@ response(Status, Headers, RespHeaders, DefaultHeaders, Body, Req=#http_req{ FullHeaders = response_merge_headers(Headers, RespHeaders, DefaultHeaders), Req2 = case OnResponse of undefined -> Req; - OnResponse -> OnResponse(Status, FullHeaders, + OnResponse -> OnResponse(Status, FullHeaders, Body, %% Don't call 'onresponse' from the hook itself. Req#http_req{resp_headers=[], resp_body= <<>>, onresponse=undefined}) -- cgit v1.2.3