diff --git a/content/src/controller/handlers/get-content-handler.ts b/content/src/controller/handlers/get-content-handler.ts index e70d2e269..5c6119610 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.url.searchParams.has('calculateContentType') 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/json' }, body: context.request.method.toUpperCase() === 'GET' ? await content.asRawStream() : undefined } }