Skip to content

Commit

Permalink
fix: Handled assigning headers in LambdaProxyWebRequest when there ar…
Browse files Browse the repository at this point in the history
…e no headers present (#2293)
  • Loading branch information
bizob2828 committed Jun 25, 2024
1 parent dbca830 commit e4d22f3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
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()
})

0 comments on commit e4d22f3

Please sign in to comment.