Mercurial > prosody-modules
comparison mod_http_logging/mod_http_logging.lua @ 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 | 569b98d6fca1 |
children | c89be016a075 |
comparison
equal
deleted
inserted
replaced
2968:569b98d6fca1 | 2969:8681729a47d5 |
---|---|
39 log_response(response, body); | 39 log_response(response, body); |
40 end | 40 end |
41 return send_response(response, body); | 41 return send_response(response, body); |
42 end | 42 end |
43 | 43 |
44 local send_file = server.send_file; | |
45 local function log_and_send_file(response, f) | |
46 if not response.finished then | |
47 log_response(response); | |
48 end | |
49 return send_file(response, f); | |
50 end | |
51 | |
44 if module.wrap_object_event then | 52 if module.wrap_object_event then |
45 -- Use object event wrapping, allows clean unloading of the module | 53 -- Use object event wrapping, allows clean unloading of the module |
46 module:wrap_object_event(server._events, false, function (handlers, event_name, event_data) | 54 module:wrap_object_event(server._events, false, function (handlers, event_name, event_data) |
47 if event_data.response then | 55 if event_data.response then |
48 event_data.response.send = log_and_send_response; | 56 event_data.response.send = log_and_send_response; |
57 event_data.response.send_file = log_and_send_file; | |
49 end | 58 end |
50 return handlers(event_name, event_data); | 59 return handlers(event_name, event_data); |
51 end); | 60 end); |
52 else | 61 else |
53 -- Fall back to monkeypatching, unlikely to behave nicely in the | 62 -- Fall back to monkeypatching, unlikely to behave nicely in the |
54 -- presence of other modules also doing this | 63 -- presence of other modules also doing this |
55 server.send_response = log_and_send_response; | 64 server.send_response = log_and_send_response; |
65 server.send_file = log_and_send_file; | |
56 function module.unload() | 66 function module.unload() |
57 server.send_response = send_response; | 67 server.send_response = send_response; |
68 server.send_file = send_file; | |
58 end | 69 end |
59 end | 70 end |