]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
http: assorted fixed to make luacheck happy
authorPetr Špaček <petr.spacek@nic.cz>
Thu, 18 Apr 2019 09:18:53 +0000 (11:18 +0200)
committerPetr Špaček <petr.spacek@nic.cz>
Thu, 18 Apr 2019 09:18:53 +0000 (11:18 +0200)
modules/http/http.lua.in
modules/http/http.test.lua
modules/http/http_doh.test.lua
modules/http/test_tls/tls.test.lua

index cdd57f37444a274aa4814eaa512f730836f69a44..34c457b494442ba1990ba09c634d5244d61336bc 100644 (file)
@@ -2,8 +2,8 @@
 if not stats then modules.load('stats') end
 if not bogus_log then modules.load('bogus_log') end
 
-ffi = require('ffi')
-cqueues = require('cqueues')
+local ffi = require('ffi')
+local cqueues = require('cqueues')
 cqueues.socket = require('cqueues.socket')
 assert(cqueues.VERSION >= 20150112)  -- fdopen changed semantics
 
@@ -320,7 +320,7 @@ end
 
 -- @function Merge dictionaries.
 -- Values from right-hand side dictionaries take precedence.
-function mergeconf(...)
+local function mergeconf(...)
        local merged = {}
        for _, intable in ipairs({...}) do
                assert(type(intable) == 'table', 'cannot merge non-tables')
@@ -331,12 +331,12 @@ function mergeconf(...)
        return merged
 end
 
-function load_cert(certname, keyname)
+local function load_cert(certname, keyname)
        local f, err = io.open(certname, 'r')
        if not f then
-               panic('[http] unable to read TLS certificate file %s: %s', certname, err)
+               panic('[http] unable to read TLS certificate file: %s', err)
        end
-       crt = x509.new(f:read('*all'))
+       local crt = x509.new(f:read('*all'))
        f:close()
        if not crt then
                panic('[http] unable to parse TLS certificate file %s', certname)
@@ -344,9 +344,9 @@ function load_cert(certname, keyname)
 
        f, err = io.open(keyname, 'r')
        if not f then
-               panic('[http] unable to open TLS key file %s: %s', keyname, err)
+               panic('[http] unable to open TLS key file: %s', err)
        end
-       key = pkey.new(f:read('*all'))
+       local key = pkey.new(f:read('*all'))
        f:close()
        if not key then
                panic('[http] unable to parse TLS key file %s', keyname)
@@ -356,7 +356,7 @@ end
 
 -- @function Listen on given socket
 -- using configuration for specific "kind" of HTTP server
-function add_socket(fd, kind)
+local function add_socket(fd, kind, addr_str)
        assert(M.servers[fd] == nil, 'socket is already served by an HTTP instance')
        local conf, crt, key
        conf = mergeconf(M.templates._builtin, M.templates._default, M.templates[kind] or {})
@@ -377,12 +377,11 @@ function add_socket(fd, kind)
        -- Compose server handler
        local routes = route(conf.endpoints)
        -- Enable SO_REUSEPORT by default (unless explicitly turned off)
-       if not reuseport and worker.id > 0 then
+       if not conf.reuseport and worker.id > 0 then
                warn('[http] the "reuseport" option is disabled and multiple forks are used, ' ..
                         'port binding will fail on some instances')
        end
-       -- Check if UNIX socket path is used
-       local addr_str  -- TODO
+       -- Check if UNIX socket path is used TODO
        conf.ctx = crt and tlscontext(crt, key)
        conf.onstream = routes
        -- Create TLS context and start listening
@@ -409,7 +408,7 @@ function add_socket(fd, kind)
 end
 
 -- @function Stop listening on given socket
-function remove_socket(fd)
+local function remove_socket(fd)
        local instance = M.servers[fd]
        assert(instance, 'HTTP module is not listening on given socket')
 
@@ -418,6 +417,19 @@ function remove_socket(fd)
        -- TODO stop refresh timer
 end
 
+-- @function Listen for config changes from net.listen()/net.close()
+local function cb_socket(...)
+       local added, endpoint, addr_str = unpack({...})
+       endpoint = ffi.cast('struct endpoint **', endpoint)[0]
+       local kind = ffi.string(endpoint.flags.kind)
+       local socket = endpoint.fd
+       if added then
+               return add_socket(socket, kind, addr_str)
+       else
+               return remove_socket(socket)
+       end
+end
+
 -- @function Init module
 function M.init()
        -- collect and merge metrics only on leader
@@ -438,19 +450,6 @@ function M.deinit()
        net.register_endpoint_kind('webmgmt')
 end
 
--- @function Listen for config changes from net.listen()/net.close()
-function cb_socket(...)
-       local added, endpoint, _ = unpack({...})
-       endpoint = ffi.cast('struct endpoint **', endpoint)[0]
-       local kind = ffi.string(endpoint.flags.kind)
-       local socket = endpoint.fd
-       if added then
-               return add_socket(socket, kind)
-       else
-               return remove_socket(socket)
-       end
-end
-
 -- @function Configure module, i.e. store new configuration template
 -- kind = socket type (doh/webmgmt)
 function M.config(conf, kind)
index bc765f58bb74bcf2c4764d12624d61aefdec1aa9..ed8f510c559f24fbd39caa19e8dcc7b3be1713d3 100644 (file)
@@ -19,7 +19,7 @@ else
        }, 'webtest')
 
        local bound
-       for i = 1,1000 do
+       for _ = 1,1000 do
                bound = net.listen('127.0.0.1', math.random(1025,65535), { kind = 'webtest'} )
                if bound then
                        break
index f9cd26b32ab0e62b810b3ecf7dddf11e00771cfe..74e1d4357d3eff003beb2bed30f519a5e321d69d 100644 (file)
@@ -88,7 +88,7 @@ else
        }, 'doh')
 
        local bound
-       for i = 1,1000 do
+       for _ = 1,1000 do
                bound = net.listen('127.0.0.1', math.random(1025,65535), { kind = 'doh'} )
                if bound then
                        break
index 0a96964531cfd4e7ba7288ed034b6de856877eca..5327e193e368b617908e080b765a7cc1f0ddd9d5 100644 (file)
@@ -15,7 +15,7 @@ else
                same(http.config(config), nil, desc .. ' can be configured')
 
                local bound
-               for i = 1,1000 do
+               for _ = 1,1000 do
                        bound = net.listen('127.0.0.1', math.random(1025,65535), { kind = 'webmgmt'} )
                        if bound then
                                break