Skip to content

Commit f690eb4

Browse files
themilchenkosergos
authored andcommitted
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 #216
1 parent b1cad8f commit f690eb4

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1313
## Fixed
1414

1515
- Do not recreate server if it's address and port were not changed (#219).
16+
- Server doesn't change after updating parameters on config reload (#216).
1617

1718
## [1.8.0] - 2025-07-07
1819

roles/httpd.lua

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,23 +107,37 @@ local function parse_params(node)
107107
}
108108
end
109109

110+
local function server_has_changed(name, node_params, 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_params) do
115+
if k ~= 'listen' and servers[name].httpd.options[k] ~= node_params[k] then
116+
return true
117+
end
118+
end
119+
return false
120+
end
121+
110122
local function apply_http(name, node)
111123
local host, port, err = parse_listen(node.listen)
112124
if err ~= nil then
113125
error("failed to parse URI: " .. err)
114126
end
115127

128+
local params = parse_params(node)
129+
116130
if servers[name] == nil then
117-
local httpd = http_server.new(host, port, parse_params(node))
131+
local httpd = http_server.new(host, port, params)
118132

119133
httpd:start()
120134
servers[name] = {
121135
httpd = httpd,
122136
routes = {},
123137
}
124-
elseif servers[name].httpd.host ~= host or servers[name].httpd.port ~= port then
138+
elseif server_has_changed(name, params, host, port) then
125139
servers[name].httpd:stop()
126-
servers[name].httpd = http_server.new(host, port, parse_params(node))
140+
servers[name].httpd = http_server.new(host, port, params)
127141
servers[name].httpd:start()
128142
end
129143
end

test/integration/httpd_role_test.lua

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,3 +233,25 @@ for log_name, log_lvl in pairs(LOG_LEVELS) do
233233
assert_should_log(log_level >= LOG_LEVELS.INFO)
234234
end
235235
end
236+
237+
g.test_enable_tls_on_config_reload = function(cg)
238+
-- We should start with no tls firstly.
239+
t.skip_if(cg.params.use_tls)
240+
241+
local resp = http_client:get('http://localhost:13000/ping')
242+
t.assert_equals(resp.status, 200, 'response not 200')
243+
t.assert_equals(resp.body, 'pong')
244+
245+
treegen.write_file(cg.server.chdir, 'config.yaml', yaml.encode(tls_config))
246+
local _, err = cg.server:eval("require('config'):reload()")
247+
t.assert_not(err)
248+
249+
resp = http_client:get('https://localhost:13000/ping', {
250+
ca_file = fio.pathjoin(ssl_data_dir, 'ca.crt')
251+
})
252+
t.assert_equals(resp.status, 200, 'response not 200')
253+
t.assert_equals(resp.body, 'pong')
254+
255+
local resp = http_client:get('http://localhost:13000/ping')
256+
t.assert_equals(resp.status, 444, 'response not 444')
257+
end

0 commit comments

Comments
 (0)