diff --git a/content/src/controller/handlers/get-content-handler.ts b/content/src/controller/handlers/get-content-handler.ts index e70d2e269..5504b0cbb 100644 --- a/content/src/controller/handlers/get-content-handler.ts +++ b/content/src/controller/handlers/get-content-handler.ts @@ -4,6 +4,7 @@ import { createContentFileHeaders } from '../utils' // Method: GET or HEAD export async function getContentHandler(context: HandlerContextWithPath<'storage', '/contents/:hashId'>) { + const shouldCalculateContentType = context.request.headers.get('Accept') === 'Any' const hash = context.params.hashId const content: ContentItem | undefined = await context.components.storage.retrieve(hash) @@ -11,9 +12,13 @@ export async function getContentHandler(context: HandlerContextWithPath<'storage throw new NotFoundError(`No content found with hash ${hash}`) } + const calculatedHeaders = await createContentFileHeaders(content, hash) + return { status: 200, - headers: await createContentFileHeaders(content, hash), + headers: shouldCalculateContentType + ? calculatedHeaders + : { ...calculatedHeaders, 'Content-Type': 'application/octet-stream' }, body: context.request.method.toUpperCase() === 'GET' ? await content.asRawStream() : undefined } } diff --git a/content/test/integration/controller/entity-metadata.spec.ts b/content/test/integration/controller/entity-metadata.spec.ts index 90cea2bd9..7f8b5e64d 100644 --- a/content/test/integration/controller/entity-metadata.spec.ts +++ b/content/test/integration/controller/entity-metadata.spec.ts @@ -98,7 +98,7 @@ describe('Integration - Get wearable image and thumbnail', () => { }) describe('image', () => { - it('when entity has not image, it should return 404', async () => { + it('when entity has not image, it should return 404 with', async () => { const deployResult = await buildDeployData(['wearable'], { metadata: { thumbnail: 'some-binary-file.png' }, contentPaths: ['test/integration/resources/some-binary-file.png'] @@ -107,8 +107,8 @@ describe('Integration - Get wearable image and thumbnail', () => { await server.deployEntity(deployResult.deployData) const responses = await Promise.all([ - fetch(`${server.getUrl()}/queries/items/wearable/image`), - fetch(`${server.getUrl()}/queries/items/wearable/image`, { method: 'HEAD' }) + fetch(`${server.getUrl()}/queries/items/wearable/image`, { headers: { Accept: 'Any' } }), + fetch(`${server.getUrl()}/queries/items/wearable/image`, { method: 'HEAD', headers: { Accept: 'Any' } }) ]) for (const response of responses) { @@ -125,8 +125,8 @@ describe('Integration - Get wearable image and thumbnail', () => { await server.deployEntity(deployResult.deployData) const responses = await Promise.all([ - fetch(`${server.getUrl()}/queries/items/wearable/image`), - fetch(`${server.getUrl()}/queries/items/wearable/image`, { method: 'HEAD' }) + fetch(`${server.getUrl()}/queries/items/wearable/image`, { headers: { Accept: 'Any' } }), + fetch(`${server.getUrl()}/queries/items/wearable/image`, { method: 'HEAD', headers: { Accept: 'Any' } }) ]) for (const response of responses) {