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