From fb5f42077838fc45bbefb1ad1583f93cccc0db79 Mon Sep 17 00:00:00 2001 From: xumin Date: Mon, 25 Dec 2023 16:54:49 +0800 Subject: [PATCH] fix(plugin): respect letter case of headers' new names Fix KAG-2599 #11579 --- .../kong/fix_req_transformer_case_sensitive.yml | 3 +++ kong/plugins/request-transformer/access.lua | 2 +- .../36-request-transformer/02-access_spec.lua | 10 +++++----- 3 files changed, 9 insertions(+), 6 deletions(-) create mode 100644 changelog/unreleased/kong/fix_req_transformer_case_sensitive.yml diff --git a/changelog/unreleased/kong/fix_req_transformer_case_sensitive.yml b/changelog/unreleased/kong/fix_req_transformer_case_sensitive.yml new file mode 100644 index 000000000000..02369e95ef44 --- /dev/null +++ b/changelog/unreleased/kong/fix_req_transformer_case_sensitive.yml @@ -0,0 +1,3 @@ +message: "**request-transformer**: now the plugin respect the letter case of new names when renaming headers." +type: bugfix +scope: Plugin diff --git a/kong/plugins/request-transformer/access.lua b/kong/plugins/request-transformer/access.lua index 76c7c5dc0fd8..441cb6b80cd0 100644 --- a/kong/plugins/request-transformer/access.lua +++ b/kong/plugins/request-transformer/access.lua @@ -168,7 +168,7 @@ local function transform_headers(conf, template_env) old_name = old_name:lower() local value = headers[old_name] if value then - headers[new_name:lower()] = value + headers[new_name] = value headers[old_name] = nil headers_to_remove[old_name] = true end diff --git a/spec/03-plugins/36-request-transformer/02-access_spec.lua b/spec/03-plugins/36-request-transformer/02-access_spec.lua index 76687101d62c..945efb7b60e6 100644 --- a/spec/03-plugins/36-request-transformer/02-access_spec.lua +++ b/spec/03-plugins/36-request-transformer/02-access_spec.lua @@ -227,7 +227,7 @@ describe("Plugin: request-transformer(access) [#" .. strategy .. "]", function() name = "request-transformer", config = { rename = { - headers = {"x-to-rename:x-is-renamed"}, + headers = {"x-to-rename:X-Is-Renamed"}, querystring = {"originalparam:renamedparam"}, body = {"originalparam:renamedparam"} } @@ -712,7 +712,7 @@ describe("Plugin: request-transformer(access) [#" .. strategy .. "]", function() assert.response(r).has.status(200) assert.response(r).has.jsonbody() assert.request(r).has.no.header("x-to-rename") - assert.request(r).has.header("x-is-renamed") + assert.request(r).has.header("X-Is-Renamed") assert.request(r).has.header("x-another-header") end) it("does not add as new header if header does not exist", function() @@ -738,13 +738,13 @@ describe("Plugin: request-transformer(access) [#" .. strategy .. "]", function() headers = { host = "test9.test", ["x-to-rename"] = "new-result", - ["x-is-renamed"] = "old-result", + ["X-Is-Renamed"] = "old-result", } }) assert.response(r).has.status(200) assert.response(r).has.jsonbody() assert.request(r).has.no.header("x-to-rename") - local h_is_renamed = assert.request(r).has.header("x-is-renamed") + local h_is_renamed = assert.request(r).has.header("X-Is-Renamed") assert.equals("new-result", h_is_renamed) end) for _, seq in ipairs({ 1, 2, 3, 4, 5, 6}) do @@ -761,7 +761,7 @@ describe("Plugin: request-transformer(access) [#" .. strategy .. "]", function() assert.response(r).has.status(200) assert.response(r).has.jsonbody() assert.request(r).has.no.header("x-to-rename") - local h_is_renamed = assert.request(r).has.header("x-is-renamed") + local h_is_renamed = assert.request(r).has.header("X-Is-Renamed") assert.equals("new-result", h_is_renamed) end) end