Skip to content

Commit

Permalink
fix(plugins): Request-Transformer rename behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
StarlightIbuki committed Jul 10, 2024
1 parent 4664b90 commit e3337af
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 8 deletions.
3 changes: 3 additions & 0 deletions changelog/unreleased/kong/req-trans-rename.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
message: "**Request-Transformer**: Fixed an issue where renamed query parameters, url-encoded body parameters, and json body parameters were not handled properly when target name is the same as the source name in the request."
type: feature
scope: Plugin
22 changes: 14 additions & 8 deletions kong/plugins/request-transformer/access.lua
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,10 @@ local function transform_querystrings(conf, template_env)
-- Rename querystring(s)
for _, old_name, new_name in iter(conf.rename.querystring, template_env) do
local value = querystring[old_name]
querystring[new_name] = value
querystring[old_name] = nil
if value then
querystring[old_name] = nil
querystring[new_name] = value
end
end

for _, name, value in iter(conf.replace.querystring, template_env) do
Expand Down Expand Up @@ -276,9 +278,11 @@ local function transform_json_body(conf, body, content_length, template_env)
if content_length > 0 and #conf.rename.body > 0 then
for _, old_name, new_name in iter(conf.rename.body, template_env) do
local value = parameters[old_name]
parameters[new_name] = value
parameters[old_name] = nil
renamed = true
if value then
parameters[old_name] = nil
parameters[new_name] = value
renamed = true
end
end
end

Expand Down Expand Up @@ -327,9 +331,11 @@ local function transform_url_encoded_body(conf, body, content_length, template_e
if content_length > 0 and #conf.rename.body > 0 then
for _, old_name, new_name in iter(conf.rename.body, template_env) do
local value = parameters[old_name]
parameters[new_name] = value
parameters[old_name] = nil
renamed = true
if value then
parameters[old_name] = nil
parameters[new_name] = value
renamed = true
end
end
end

Expand Down
25 changes: 25 additions & 0 deletions spec/01-unit/31-kong_cache_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
local cache = require "kong.cache"

local helpers = require "spec.helpers"

local REDIS_HOST = helpers.redis_host
local REDIS_PORT = helpers.redis_port

describe("kong.cache", function()
describe("redis strategy", function()
lazy_setup(function()
cache.new("my_cache", {
shm_name = "my_cache",
cluster_events = cluster_events,
worker_events = worker_events,
ttl = db_cache_ttl,
neg_ttl = db_cache_neg_ttl or db_cache_ttl,
resurrect_ttl = kong_config.resurrect_ttl,
page = page,
cache_pages = cache_pages,
resty_lock_opts = LOCK_OPTS,
lru_size = get_lru_size(kong_config),
})
end)
end)
end

0 comments on commit e3337af

Please sign in to comment.