]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
http: allow loading custom endpoints to http
authorMarek Vavruša <mvavrusa@cloudflare.com>
Wed, 21 Mar 2018 22:57:19 +0000 (15:57 -0700)
committerMarek Vavruša <mvavrusa@cloudflare.com>
Fri, 7 Sep 2018 17:45:21 +0000 (10:45 -0700)
Previously the module was created on configuration time, so it wasn't
possible to inject custom endpoints to the default interface.

modules/http/http.lua
modules/http/http.test.lua

index f3c4e493690105354163d4f866f8e96dcd54ecaf..f2fe506a8445c8883f544093a303dab6a3e7bd00 100644 (file)
@@ -380,7 +380,13 @@ function M.config(conf)
                        error('[http] mmdblua library not found, please remove GeoIP configuration')
                end
        end
-       M.add_interface(conf)
+
+       -- Add endpoints to default endpoints
+       local endpoints = conf.endpoints or {}
+       for k, v in pairs(M.endpoints) do
+               endpoints[k] = v
+       end
+       M.interface(conf.host, conf.port, endpoints, conf.cert, conf.key)
 end
 
 return M
index e22024b9be7e068378d6c125d6c35e4dd6b0a521..198dd0abf2417024ec390c983131469df8d57721 100644 (file)
@@ -5,17 +5,13 @@ if not has_http then
        done()
 else
        local request = require('http.request')
-       local endpoints = require('http').endpoints
-
-       -- custom endpoints
-       endpoints['/test'] = {'text/custom', function () return 'hello' end}
 
        -- setup resolver
        modules = {
                http = {
                        port = 0, -- Select random port
                        cert = false,
-                       endpoints = endpoints,
+                       endpoints = { ['/test'] = {'text/custom', function () return 'hello' end} },
                }
        }