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: Handled assigning headers in LambdaProxyWebRequest when there are no headers present #2293

Merged
merged 1 commit into from
Jun 25, 2024
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
2 changes: 1 addition & 1 deletion lib/serverless/api-gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function normalizeHeaders(event, lowerCaseKey = false) {
const headers = event.multiValueHeaders ?? event.headers

if (!headers) {
return
return {}
}

return Object.fromEntries(
Expand Down
14 changes: 14 additions & 0 deletions test/unit/serverless/api-gateway-v2.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,3 +272,17 @@ tap.test('should capture request headers', (t) => {
t.end()
}
})

tap.test('should not crash when headers are non-existent', (t) => {
const { lambda, event, functionContext, responseBody } = t.context
delete event.headers

const wrappedHandler = lambda.patchLambdaHandler((event, context, callback) => {
callback(null, responseBody)
})

t.doesNotThrow(() => {
wrappedHandler(event, functionContext, () => {})
})
t.end()
})
Loading