From 864e81060c9d12b9f321d09b82484515923ada1e Mon Sep 17 00:00:00 2001 From: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com> Date: Wed, 10 Apr 2024 16:21:19 -0700 Subject: [PATCH] fix: identity CIDs use contentTypeParser --- packages/verified-fetch/src/verified-fetch.ts | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/packages/verified-fetch/src/verified-fetch.ts b/packages/verified-fetch/src/verified-fetch.ts index 598eff0e..0d155326 100644 --- a/packages/verified-fetch/src/verified-fetch.ts +++ b/packages/verified-fetch/src/verified-fetch.ts @@ -423,18 +423,13 @@ export class VerifiedFetch { // if the user has specified an `Accept` header that corresponds to a raw // type, honour that header, so for example they don't request // `application/vnd.ipld.raw` but get `application/octet-stream` - const overriddenContentType = getOverridenRawContentType({ headers: options?.headers, accept }) - if (overriddenContentType != null) { - response.headers.set('content-type', overriddenContentType) - } else { - await this.setContentType(result, path, response) - } + await this.setContentType(result, path, response, getOverridenRawContentType({ headers: options?.headers, accept })) return response } - private async setContentType (bytes: Uint8Array, path: string, response: Response): Promise { - let contentType = 'application/octet-stream' + private async setContentType (bytes: Uint8Array, path: string, response: Response, defaultContentType = 'application/octet-stream'): Promise { + let contentType: string | undefined if (this.contentTypeParser != null) { try { @@ -456,7 +451,7 @@ export class VerifiedFetch { } } this.log.trace('setting content type to "%s"', contentType) - response.headers.set('content-type', contentType) + response.headers.set('content-type', contentType ?? defaultContentType) } /**