Mercurial > prosody-modules
comparison mod_http_logging/mod_http_logging.lua @ 2968:569b98d6fca1
mod_http_logging: Be robust against missing connection object
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 30 Mar 2018 13:37:39 +0200 |
parents | 135ca695fcbf |
children | 8681729a47d5 |
comparison
equal
deleted
inserted
replaced
2967:135ca695fcbf | 2968:569b98d6fca1 |
---|---|
22 end | 22 end |
23 | 23 |
24 local function log_response(response, body) | 24 local function log_response(response, body) |
25 local len = tostring(get_content_len(response, body) or "-"); | 25 local len = tostring(get_content_len(response, body) or "-"); |
26 local request = response.request; | 26 local request = response.request; |
27 local ip = request.ip or request.conn:ip(); | 27 local ip = request.ip; |
28 if not ip and request.conn then | |
29 ip = request.conn:ip(); | |
30 end | |
28 local req = string.format("%s %s HTTP/%s", request.method, request.path, request.httpversion); | 31 local req = string.format("%s %s HTTP/%s", request.method, request.path, request.httpversion); |
29 local date = os.date("%d/%m/%Y:%H:%M:%S %z"); | 32 local date = os.date("%d/%m/%Y:%H:%M:%S %z"); |
30 module:log("info", "%s - - [%s] \"%s\" %d %s", ip, date, req, response.status_code, len); | 33 module:log("info", "%s - - [%s] \"%s\" %d %s", ip, date, req, response.status_code, len); |
31 end | 34 end |
32 | 35 |