Skip to content

Commit 20669d1

Browse files
committed
roles: update opts on config reload
There were no way to update config on the run with method `config:reload()` instead of listen parameters. This patch fixes it, all options support config reload. Closes #126
1 parent 9da959c commit 20669d1

2 files changed

Lines changed: 34 additions & 1 deletion

File tree

roles/httpd.lua

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,20 @@ local function parse_params(node)
107107
}
108108
end
109109

110+
local function server_was_changed(name, node, host, port)
111+
if servers[name].httpd.host ~= host or servers[name].httpd.port ~= port then
112+
return true
113+
end
114+
for k in pairs(node) do
115+
if k ~= 'listen' then
116+
if servers[name].httpd.options[k] ~= node[k] then
117+
return true
118+
end
119+
end
120+
end
121+
return false
122+
end
123+
110124
local function apply_http(name, node)
111125
local host, port, err = parse_listen(node.listen)
112126
if err ~= nil then
@@ -121,7 +135,7 @@ local function apply_http(name, node)
121135
httpd = httpd,
122136
routes = {},
123137
}
124-
elseif servers[name].httpd.host ~= host or servers[name].httpd.port ~= port then
138+
elseif server_was_changed(name, node, host, port) then
125139
servers[name].httpd:stop()
126140
servers[name].httpd = http_server.new(host, port, parse_params(node))
127141
servers[name].httpd:start()

test/integration/httpd_role_test.lua

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,3 +203,22 @@ for _, log_lvl in pairs(LOG_LEVELS) do
203203
assert_should_log(log_level >= LOG_LEVELS.INFO)
204204
end
205205
end
206+
207+
g.test_enable_tls_on_config_reload = function(cg)
208+
-- We should start with no tls firstly.
209+
t.skip_if(cg.params.use_tls)
210+
211+
local resp = http_client:get('http://localhost:13000/ping')
212+
t.assert_equals(resp.status, 200, 'response not 200')
213+
t.assert_equals(resp.body, 'pong')
214+
215+
treegen.write_file(cg.server.chdir, 'config.yaml', yaml.encode(tls_config))
216+
local _, err = cg.server:eval("require('config'):reload()")
217+
t.assert_not(err)
218+
219+
resp = http_client:get('https://localhost:13000/ping', {
220+
ca_file = fio.pathjoin(ssl_data_dir, 'ca.crt')
221+
})
222+
t.assert_equals(resp.status, 200, 'response not 200')
223+
t.assert_equals(resp.body, 'pong')
224+
end

0 commit comments

Comments
 (0)