Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(pdk): response send function should ignore transfer-encoding correctly #11936

Merged
merged 4 commits into from
Nov 8, 2023
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
message: Fix an issue that when using kong.response.exit, the Transfer-Encoding header set by user is not removed
type: bugfix
scope: PDK
1 change: 0 additions & 1 deletion kong/pdk/response.lua
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,6 @@ local function new(self, major_version)
local has_content_length
if headers ~= nil then
for name, value in pairs(headers) do
ngx.header[name] = normalize_multi_header(value)
local lower_name = lower(name)
if lower_name == "transfer-encoding" or lower_name == "transfer_encoding" then
self.log.warn("manually setting Transfer-Encoding. Ignored.")
Expand Down
37 changes: 37 additions & 0 deletions spec/03-plugins/27-aws-lambda/99-access_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ for _, strategy in helpers.each_strategy() do
service = null,
}

local route24 = bp.routes:insert {
hosts = { "lambda24.com" },
protocols = { "http", "https" },
service = null,
}

bp.plugins:insert {
name = "aws-lambda",
route = { id = route1.id },
Expand Down Expand Up @@ -463,6 +469,19 @@ for _, strategy in helpers.each_strategy() do
}
}

bp.plugins:insert {
name = "aws-lambda",
route = { id = route24.id },
config = {
port = 10001,
aws_key = "mock-key",
aws_secret = "mock-secret",
aws_region = "us-east-1",
function_name = "functionWithTransferEncodingHeader",
is_proxy_integration = true,
}
}

fixtures.dns_mock:A({
name = "custom.lambda.endpoint",
address = "127.0.0.1",
Expand Down Expand Up @@ -1148,6 +1167,24 @@ for _, strategy in helpers.each_strategy() do
assert.equals("https", req.vars.scheme)
end)

it("#test2 works normally by removing transfer encoding header when proxy integration mode", function ()
proxy_client:set_timeout(3000)
assert.eventually(function ()
local res = assert(proxy_client:send({
method = "GET",
path = "/get",
headers = {
["Host"] = "lambda24.com"
}
}))

assert.res_status(200, res)
assert.is_nil(res.headers["Transfer-Encoding"])
assert.is_nil(res.headers["transfer-encoding"])

return true
end).with_timeout(3).is_truthy()
end)
end)

describe("AWS_REGION environment is set", function()
Expand Down
3 changes: 3 additions & 0 deletions spec/fixtures/aws-lambda.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ local fixtures = {
elseif string.match(ngx.var.uri, "functionEcho") then
require("spec.fixtures.mock_upstream").send_default_json_response()

elseif string.match(ngx.var.uri, "functionWithTransferEncodingHeader") then
windmgc marked this conversation as resolved.
Show resolved Hide resolved
ngx.say("{\"statusCode\": 200, \"headers\": { \"Transfer-Encoding\": \"chunked\", \"transfer-encoding\": \"chunked\"}}")

elseif type(res) == 'string' then
ngx.header["Content-Length"] = #res + 1
ngx.say(res)
Expand Down
5 changes: 3 additions & 2 deletions t/01-pdk/08-response/11-exit.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use Test::Nginx::Socket::Lua;
use Test::Nginx::Socket::Lua::Stream;
do "./t/Util.pm";

plan tests => repeat_each() * (blocks() * 4) + 11;
plan tests => repeat_each() * (blocks() * 4) + 12;

run_tests();

Expand Down Expand Up @@ -1128,7 +1128,7 @@ finalize stream session: 200



=== TEST 18: response.exit() does not set transfer-encoding from headers
=== TEST 44: response.exit() does not set transfer-encoding from headers
--- http_config eval: $t::Util::HttpConfig
--- config
location = /t {
Expand All @@ -1148,6 +1148,7 @@ GET /t
--- response_body
test
--- response_headers
! Transfer-Encoding
Content-Length: 5
X-test: test
--- error_log
Expand Down