Skip to content

Commit 5aa3fa9

Browse files
committed
feat: only parse on json content-type
1 parent a74a2d4 commit 5aa3fa9

File tree

3 files changed

+43
-24
lines changed

3 files changed

+43
-24
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/http/handler.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,15 @@ export const createHttpHandler =
109109
};
110110

111111
function parseBody<T>(event: AWSLambda.APIGatewayProxyEventV2): T {
112-
if (!event.body || !event.isBase64Encoded) {
113-
return JSON.parse(event.body ?? '{}');
112+
let body = event.body;
113+
if (event.body && event.isBase64Encoded) {
114+
const buff = Buffer.from(event.body!, 'base64');
115+
body = buff.toString('utf8');
114116
}
115-
const buff = Buffer.from(event.body, 'base64');
116-
return JSON.parse(buff.toString('utf8'));
117+
if (event.headers && event.headers['content-type']?.includes('application/json')) {
118+
return JSON.parse(body ?? '{}');
119+
}
120+
return body as any;
117121
}
118122

119123
function corsHeader(event: AWSLambda.APIGatewayProxyEventV2): { [name: string]: string } {

yarn.lock

Lines changed: 32 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)