You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What runtime/platform is your app running on? (with version if possible)
AWS Lambda/NodeJS 20
What steps can reproduce the bug?
If an incoming request event has multiValueHeaders set, then headers will be set in both headers and multiValueHeaders in the response, resulting in duplicated header values in the final HTTP response. The AWS docs describe this behaviour:
If you specify values for both headers and multiValueHeaders, API Gateway merges them into a single list. If the same key-value pair is specified in both, only the values from multiValueHeaders will appear in the merged list.
The initialization of multiValueHeaders in result seems wrong, why does the incoming event alter the structure of the outgoing response? Surely multiValueHeaders should be initialized if there's multi-valued headers in res.headers.
If result.multiValueHeaders is initialized (because the incoming event had multiValueHeaders) then the subsequent loop will set a header in both result.headers and result.multiValueHeaders which is incorrect. API Gateway will merge both these fields in the final HTTP response.
I think the correct behaviour should be to either:
Detect if there a header has multiple values in res.headers and only set it in multiValueHeaders, otherwise only set it in headers. Never set it in both.
Just set every header in multiValueHeaders even if there's only a single value, and never set headers.
The multiValueHeaders key can contain multi-value headers as well as single-value headers. You can use the multiValueHeaders key to specify all of your extra headers, including any single-value ones.
What is the expected behavior?
Headers should not be duplicated.
What do you see instead?
No response
Additional information
No response
The text was updated successfully, but these errors were encountered:
What version of Hono are you using?
4.6.17
What runtime/platform is your app running on? (with version if possible)
AWS Lambda/NodeJS 20
What steps can reproduce the bug?
If an incoming request event has
multiValueHeaders
set, then headers will be set in bothheaders
andmultiValueHeaders
in the response, resulting in duplicated header values in the final HTTP response. The AWS docs describe this behaviour:This whole block looks suspicious to me:
hono/src/adapter/aws-lambda/handler.ts
Lines 240 to 254 in d72aa4b
multiValueHeaders
inresult
seems wrong, why does the incoming event alter the structure of the outgoing response? SurelymultiValueHeaders
should be initialized if there's multi-valued headers inres.headers
.result.multiValueHeaders
is initialized (because the incoming event hadmultiValueHeaders
) then the subsequent loop will set a header in bothresult.headers
andresult.multiValueHeaders
which is incorrect. API Gateway will merge both these fields in the final HTTP response.I think the correct behaviour should be to either:
res.headers
and only set it inmultiValueHeaders
, otherwise only set it inheaders
. Never set it in both.multiValueHeaders
even if there's only a single value, and never setheaders
.The AWS docs suggest (2) is acceptable:
What is the expected behavior?
Headers should not be duplicated.
What do you see instead?
No response
Additional information
No response
The text was updated successfully, but these errors were encountered: