Skip to content

Commit e4d22f3

Browse files
authoredJun 25, 2024··
fix: Handled assigning headers in LambdaProxyWebRequest when there are no headers present (#2293)
1 parent dbca830 commit e4d22f3

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed
 

‎lib/serverless/api-gateway.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ function normalizeHeaders(event, lowerCaseKey = false) {
8080
const headers = event.multiValueHeaders ?? event.headers
8181

8282
if (!headers) {
83-
return
83+
return {}
8484
}
8585

8686
return Object.fromEntries(

‎test/unit/serverless/api-gateway-v2.test.js

+14
Original file line numberDiff line numberDiff line change
@@ -272,3 +272,17 @@ tap.test('should capture request headers', (t) => {
272272
t.end()
273273
}
274274
})
275+
276+
tap.test('should not crash when headers are non-existent', (t) => {
277+
const { lambda, event, functionContext, responseBody } = t.context
278+
delete event.headers
279+
280+
const wrappedHandler = lambda.patchLambdaHandler((event, context, callback) => {
281+
callback(null, responseBody)
282+
})
283+
284+
t.doesNotThrow(() => {
285+
wrappedHandler(event, functionContext, () => {})
286+
})
287+
t.end()
288+
})

0 commit comments

Comments
 (0)
Please sign in to comment.