Skip to content
This repository has been archived by the owner on Aug 27, 2021. It is now read-only.

Commit

Permalink
fix(handler) ensure multivalueheaders are handled
Browse files Browse the repository at this point in the history
Ensure the `multiValueHeaders` field is handled in AWS Lambda proxy
integration responses.

Fix #53.
  • Loading branch information
gszr committed Jun 9, 2021
1 parent 3376a3e commit 048a37f
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
7 changes: 7 additions & 0 deletions kong/plugins/aws-lambda/handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ local function extract_proxy_response(content)
body = ngx_decode_base64(body)
end

local multiValueHeaders = serialized_content.multiValueHeaders
if multiValueHeaders then
for header, values in pairs(multiValueHeaders) do
headers[header] = values
end
end

headers["Content-Length"] = #body

return {
Expand Down
2 changes: 2 additions & 0 deletions spec/fixtures/aws-lambda.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ local fixtures = {
elseif string.match(ngx.var.uri, "functionWithBase64EncodedResponse") then
ngx.say("{\"statusCode\": 200, \"body\": \"dGVzdA==\", \"isBase64Encoded\": true}")
elseif string.match(ngx.var.uri, "functionWithMultiValueHeadersResponse") then
ngx.say("{\"statusCode\": 200, \"headers\": { \"Age\": \"3600\"}, \"multiValueHeaders\": {\"Access-Control-Allow-Origin\": [\"site1.com\", \"site2.com\"]}}")
elseif type(res) == 'string' then
ngx.header["Content-Length"] = #res + 1
Expand Down
31 changes: 31 additions & 0 deletions spec/plugins/aws-lambda/99-access_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ for _, strategy in helpers.each_strategy() do
service = null,
}

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

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

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

assert(helpers.start_kong({
database = strategy,
plugins = "aws-lambda",
Expand Down Expand Up @@ -898,6 +917,18 @@ for _, strategy in helpers.each_strategy() do
assert.res_status(200, res)
assert.equal("test", res:read_body())
end)
it("returns multivalueheaders response from a Lambda function #o", function()
local res = assert(proxy_client:send {
method = "GET",
path = "/get?key1=some_value1&key2=some_value2&key3=some_value3",
headers = {
["Host"] = "lambda17.com"
}
})
assert.res_status(200, res)
assert.is_string(res.headers.age)
assert.is_array(res.headers["Access-Control-Allow-Origin"])
end)
end)
end)
end

0 comments on commit 048a37f

Please sign in to comment.