]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
modules/http: added an error handler to HTTP streams
authorMarek Vavruša <mvavrusa@cloudflare.com>
Mon, 2 Apr 2018 23:42:42 +0000 (16:42 -0700)
committerMarek Vavruša <mvavrusa@cloudflare.com>
Fri, 7 Sep 2018 17:45:21 +0000 (10:45 -0700)
Instead of throwing an error in the HTTP handler, server should log it.
This covers errors like client disconnecting before reading the response
body etc.

modules/http/http.lua

index f2fe506a8445c8883f544093a303dab6a3e7bd00..c0df9400416160a444d848d25c5ab6bd7178180f 100644 (file)
@@ -322,6 +322,16 @@ function M.add_interface(conf)
                ctx = crt and tlscontext(crt, key),
                tls = conf.tls,
                onstream = routes,
+               -- Log errors, but do not throw
+               onerror = function(myserver, context, op, err, errno) -- luacheck: ignore 212
+                       local msg = '[http] ' .. op .. ' on ' .. tostring(context) .. ' failed'
+                       if err then
+                               msg = msg .. ': ' .. tostring(err)
+                       end
+                       if verbose() then
+                               log(msg)
+                       end
+               end,
        }
        -- Manually call :listen() so that we are bound before calling :localname()
        if s then