From c3abb6aaa6e16136a8ed8b4207e2a022bf1d64a6 Mon Sep 17 00:00:00 2001 From: xumin Date: Fri, 5 Jan 2024 10:49:47 +0800 Subject: [PATCH] Revert "fix(request-transformer): respect letter case of rename headers' new names (#12244)" This reverts commit 30154217e03d7b77675716e0728609b19518dc73. --- .../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, 6 insertions(+), 9 deletions(-) delete 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 deleted file mode 100644 index 02369e95ef44..000000000000 --- a/changelog/unreleased/kong/fix_req_transformer_case_sensitive.yml +++ /dev/null @@ -1,3 +0,0 @@ -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 441cb6b80cd0..76c7c5dc0fd8 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] = value + headers[new_name:lower()] = 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 945efb7b60e6..76687101d62c 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