diff --git a/src/http/routes/s3/index.ts b/src/http/routes/s3/index.ts index 6be0a5fe..65e15cc3 100644 --- a/src/http/routes/s3/index.ts +++ b/src/http/routes/s3/index.ts @@ -117,6 +117,15 @@ export default async function routes(fastify: FastifyInstance) { (route) => route.disableContentTypeParser ) + if (disableContentParser) { + localFastify.addContentTypeParser( + ['application/json', 'text/plain', 'application/xml'], + function (request, payload, done) { + done(null) + } + ) + } + localFastify.register(fastifyMultipart, { limits: { fields: 20, diff --git a/src/test/s3-protocol.test.ts b/src/test/s3-protocol.test.ts index 1a889384..221b54ad 100644 --- a/src/test/s3-protocol.test.ts +++ b/src/test/s3-protocol.test.ts @@ -562,6 +562,20 @@ describe('S3 Protocol', () => { expect(resp.$metadata.httpStatusCode).toEqual(200) }) + it('upload a broken JSON body using putObject ', async () => { + const bucketName = await createBucket(client) + + const putObject = new PutObjectCommand({ + Bucket: bucketName, + Key: 'test-1-put-object.jpg', + ContentType: 'application/json', + Body: '{"hello": "world"', // (no-closing tag) + }) + + const resp = await client.send(putObject) + expect(resp.$metadata.httpStatusCode).toEqual(200) + }) + it('upload a file using putObject with custom metadata', async () => { const bucketName = await createBucket(client)