Skip to content

Commit c8d9fd8

Browse files
authored
fix: disable content type parsers on upload (#618)
1 parent 53cd5d6 commit c8d9fd8

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/http/routes/s3/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,15 @@ export default async function routes(fastify: FastifyInstance) {
117117
(route) => route.disableContentTypeParser
118118
)
119119

120+
if (disableContentParser) {
121+
localFastify.addContentTypeParser(
122+
['application/json', 'text/plain', 'application/xml'],
123+
function (request, payload, done) {
124+
done(null)
125+
}
126+
)
127+
}
128+
120129
localFastify.register(fastifyMultipart, {
121130
limits: {
122131
fields: 20,

src/test/s3-protocol.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,20 @@ describe('S3 Protocol', () => {
562562
expect(resp.$metadata.httpStatusCode).toEqual(200)
563563
})
564564

565+
it('upload a broken JSON body using putObject ', async () => {
566+
const bucketName = await createBucket(client)
567+
568+
const putObject = new PutObjectCommand({
569+
Bucket: bucketName,
570+
Key: 'test-1-put-object.jpg',
571+
ContentType: 'application/json',
572+
Body: '{"hello": "world"', // (no-closing tag)
573+
})
574+
575+
const resp = await client.send(putObject)
576+
expect(resp.$metadata.httpStatusCode).toEqual(200)
577+
})
578+
565579
it('upload a file using putObject with custom metadata', async () => {
566580
const bucketName = await createBucket(client)
567581

0 commit comments

Comments
 (0)