From: Petr Špaček Date: Tue, 31 Mar 2020 13:35:37 +0000 (+0200) Subject: http: also log results of HTTP requests X-Git-Tag: v5.1.0~21^2~12 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=dc682fd23d206a5e681599d3437463f4ed3db2ef;p=thirdparty%2Fknot-resolver.git http: also log results of HTTP requests --- diff --git a/modules/http/http.lua.in b/modules/http/http.lua.in index 6a46ac736..c3a52cf5f 100644 --- a/modules/http/http.lua.in +++ b/modules/http/http.lua.in @@ -222,13 +222,14 @@ local function route(endpoints) local h = assert(stream:get_headers()) local m = h:get(':method') local path = h:get(':path') - if verbose() then - log('[http] %s %s HTTP/%d', m, path, connection.version) - end -- Upgrade connection to WebSocket local ws = http_websocket.new_from_stream(stream, h) if ws then + if verbose() then + log('[http] %s %s HTTP/%d web socket open', + m, path, connection.version) + end assert(ws:accept { protocols = {'json'} }) -- Continue streaming results to client local ep = endpoints[path] @@ -237,23 +238,34 @@ local function route(endpoints) cb(h, ws) end ws:close() + if verbose() then + log('[http] %s %s HTTP/%d web socket closed', + m, path, connection.version) + end return else local ok, err, reason = http_util.yieldable_pcall(serve, endpoints, h, stream) if not ok or err then - if err ~= '404' and verbose() then - log('[http] %s %s: %s (%s)', m, path, err or '500', reason) + err = err or '500' + if verbose() then + log('[http] %s %s HTTTP/%d %s %s', + m, path, connection.version, err, reason or '') end -- Method is not supported local hsend = http_headers.new() - hsend:append(':status', err or '500') + hsend:append(':status', err) if reason then assert(stream:write_headers(hsend, false)) assert(stream:write_chunk(reason, true)) else assert(stream:write_headers(hsend, true)) end + else if verbose() then + log('[http] %s %s HTTP/%d 200', + m, path, connection.version) + end end + end end end