Skip to content

Commit 5120ade

Browse files
authored
fix(lib): change default headers to empty table instead of an array to remove deprecation notice (#174)
--------- Signed-off-by: Jay Chen <1180092+jijiechen@users.noreply.github.com>
1 parent 6e5b09b commit 5120ade

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

lib/resty/healthcheck.lua

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,6 +1037,8 @@ function checker:run_single_check(ip, port, hostname, hostheader)
10371037
local headers
10381038
if self.checks.active._headers_str then
10391039
headers = self.checks.active._headers_str
1040+
elseif req_headers == nil then
1041+
headers = ""
10401042
else
10411043
local headers_length = nkeys(req_headers)
10421044
if headers_length > 0 then
@@ -1424,6 +1426,7 @@ end
14241426

14251427

14261428
local NO_DEFAULT = {}
1429+
local NO_DEFAULT_NON_NESTED = { ["__non_nested"] = "" } -- value that accepts a top level table
14271430
local MAXNUM = 2^31 - 1
14281431

14291432

@@ -1448,7 +1451,7 @@ local function fill_in_settings(opts, defaults, ctx)
14481451

14491452
if v ~= nil then
14501453
if type(v) == "table" then
1451-
if default[1] then -- do not recurse on arrays
1454+
if default == NO_DEFAULT_NON_NESTED or default[1] then -- do not recurse on non-nested tables or arrays
14521455
obj[k] = v
14531456
else
14541457
ctx[#ctx + 1] = k
@@ -1461,7 +1464,7 @@ local function fill_in_settings(opts, defaults, ctx)
14611464
end
14621465
obj[k] = v
14631466
end
1464-
elseif default ~= NO_DEFAULT then
1467+
elseif default ~= NO_DEFAULT and default ~= NO_DEFAULT_NON_NESTED then -- do not assign dummy default values
14651468
obj[k] = default
14661469
end
14671470

@@ -1484,7 +1487,7 @@ local function get_defaults()
14841487
http_path = "/",
14851488
https_sni = NO_DEFAULT,
14861489
https_verify_certificate = true,
1487-
headers = {""},
1490+
headers = NO_DEFAULT_NON_NESTED,
14881491
healthy = {
14891492
interval = 0, -- 0 = disabled by default
14901493
http_statuses = { 200, 302 },

0 commit comments

Comments
 (0)