8000 fix(admin): allow bidirectional format conversion for upstream.nodes in PATCH requests by janiussyafiq · Pull Request #13065 · apache/apisix · GitHub
[go: up one dir, main page]

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions apisix/core/table.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ local ipairs = ipairs
local pairs = pairs
local type = type
local ngx_re = require("ngx.re")
local isarray = require("table.isarray")


local _M = {
Expand Down Expand Up @@ -174,10 +175,10 @@ local function merge(origin, extend)
for k,v in pairs(extend) do
if type(v) == "table" then
if type(origin[k] or false) == "table" then
if _M.nkeys(origin[k]) ~= #origin[k] then
merge(origin[k] or {}, extend[k] or {})
else
if isarray(origin[k]) or isarray(v) then
origin[k] = v
else
merge(origin[k] or {}, extend[k] or {})
end
else
origin[k] = v
Expand Down
74 changes: 74 additions & 0 deletions t/admin/routes-array-nodes.t
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,77 @@ passed
GET /t
--- response_body
passed



=== TEST 3: PATCH route from array nodes to hash table nodes
--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test

local code, body = t('/apisix/admin/routes/1',
ngx.HTTP_PUT,
[[{
"uri": "/index.html",
"upstream": {
"nodes": [{
"host": "127.0.0.1",
"port": 8080,
"weight": 1
}],
"type": "roundrobin"
}
}]]
)

if code >= 300 then
ngx.status = code
ngx.say(body)
return
end

code, body = t('/apisix/admin/routes/1',
ngx.HTTP_PATCH,
[[{
"upstream": {
"nodes": {
"127.0.0.1:9200": 1
}
}
}]]
)

if code >= 300 then
ngx.status = code
ngx.say(body)
return
end

code, body = t('/apisix/admin/routes/1',
ngx.HTTP_PATCH,
[[{
"upstream": {
"nodes": [{
"host": "127.0.0.1",
"port": 8080,
"weight": 1
}],
"type": "roundrobin"
}
}]]
)

if code >= 300 then
ngx.status = code
ngx.say(body)
return
end

ngx.say(body)
}
}
--- request
GET /t
--- response_body
passed
Loading
0