Skip to content

Commit 0fd21d4

Browse files
committed
fix(validateInput): content-length may not be defined
1 parent b153398 commit 0fd21d4

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/validateInput.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ export const validateInput = <Schema extends TSchema>(
3737
let reqBody = {}
3838
const headers = parseHeaders(req.event.headers)
3939
const contentType = headers.get('content-type') ?? ''
40-
const contentLength = parseInt(headers.get('content-length') ?? '0', 10)
41-
if (contentType.includes('application/json') && contentLength > 0) {
40+
if (
41+
contentType.includes('application/json') &&
42+
(req.event.body?.length ?? 0) >= 2 // should be at least '{}'
43+
) {
4244
reqBody = tryAsJSON(req.event.body) ?? {}
4345
}
4446
const input = mapInput?.(req.event) ?? {

0 commit comments

Comments
 (0)