Skip to content

Commit

Permalink
fix: fix code
Browse files Browse the repository at this point in the history
  • Loading branch information
oowl committed Dec 20, 2023
1 parent 033186c commit 1218075
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
12 changes: 10 additions & 2 deletions kong/pdk/private/checks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,19 @@ function checks.validate_header(name, value)

local tvalue = type(value)
if tvalue ~= "string" then
if tvalue == "number" or tvalue == "boolean" then
if tvalue == "table" then
for _, vv in ipairs(value) do
local tvv = type(vv)
if tvv ~= "string" then
error(fmt("invalid header value in array %q: got %s, " ..
"expected string", name, tvv), 3)
end
end
elseif tvalue == "number" or tvalue == "boolean" then
value = tostring(value)
else
error(fmt("invalid header value for %q: got %s, expected " ..
"string, number or boolean", name, tvalue), 3)
"string, number or boolean, table", name, tvalue), 3)
end
end
return value
Expand Down
4 changes: 2 additions & 2 deletions kong/pdk/response.lua
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ local function new(self, major_version)
return
end

ngx.header[name] = normalize_header(value)
ngx.header[name] = normalize_multi_header(value)
end


Expand Down Expand Up @@ -463,7 +463,7 @@ local function new(self, major_version)

validate_header(name, value)

add_header(name, normalize_header(value))
add_header(name, normalize_multi_header(value))
end


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ describe("Plugin: response-transformer", function()
it("header rename error trace when same header was set twice", function()
local headers = get_headers({ h1 = { "v1", "v2"}})
header_transformer.transform_headers(conf, headers)
assert.same({h2 = "v1"}, headers)
assert.same({h2 = { "v1", "v2" }}, headers)
end)
end)
describe("replace", function()
Expand Down

0 comments on commit 1218075

Please sign in to comment.