Software /
code /
prosody-modules
Changeset
2969:8681729a47d5
mod_http_logging: Wrap API for sending data from file handles
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 30 Mar 2018 13:40:06 +0200 |
parents | 2968:569b98d6fca1 |
children | 2970:c5122b7633a8 |
files | mod_http_logging/mod_http_logging.lua |
diffstat | 1 files changed, 11 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/mod_http_logging/mod_http_logging.lua Fri Mar 30 13:37:39 2018 +0200 +++ b/mod_http_logging/mod_http_logging.lua Fri Mar 30 13:40:06 2018 +0200 @@ -41,11 +41,20 @@ return send_response(response, body); end +local send_file = server.send_file; +local function log_and_send_file(response, f) + if not response.finished then + log_response(response); + end + return send_file(response, f); +end + if module.wrap_object_event then -- Use object event wrapping, allows clean unloading of the module module:wrap_object_event(server._events, false, function (handlers, event_name, event_data) if event_data.response then event_data.response.send = log_and_send_response; + event_data.response.send_file = log_and_send_file; end return handlers(event_name, event_data); end); @@ -53,7 +62,9 @@ -- Fall back to monkeypatching, unlikely to behave nicely in the -- presence of other modules also doing this server.send_response = log_and_send_response; + server.send_file = log_and_send_file; function module.unload() server.send_response = send_response; + server.send_file = send_file; end end