]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
http: also log results of HTTP requests
authorPetr Špaček <petr.spacek@nic.cz>
Tue, 31 Mar 2020 13:35:37 +0000 (15:35 +0200)
committerTomas Krizek <tomas.krizek@nic.cz>
Thu, 2 Apr 2020 11:57:32 +0000 (13:57 +0200)
modules/http/http.lua.in

index 6a46ac73640bf0037962e43c01ebf76d4714dfac..c3a52cf5fd8eb429cf9d9d34f9d8b3d67ac609b3 100644 (file)
@@ -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