From fcc4436eeb6e5b076cd81f12a80b3d80aae11b29 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marek=20Vavru=C5=A1a?= Date: Wed, 21 Mar 2018 15:57:19 -0700 Subject: [PATCH] http: allow loading custom endpoints to http 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 | 8 +++++++- modules/http/http.test.lua | 6 +----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/modules/http/http.lua b/modules/http/http.lua index f3c4e4936..f2fe506a8 100644 --- a/modules/http/http.lua +++ b/modules/http/http.lua @@ -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 diff --git a/modules/http/http.test.lua b/modules/http/http.test.lua index e22024b9b..198dd0abf 100644 --- a/modules/http/http.test.lua +++ b/modules/http/http.test.lua @@ -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} }, } } -- 2.47.2