diff options
author | Andreu Botella <andreu@andreubotella.com> | 2022-03-20 14:31:12 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-20 14:31:12 +0100 |
commit | 593801e265e7609ac0bd695fcb450e479d5db776 (patch) | |
tree | ca6825cbe046fc7206f0e948dc6ddebe14319d3f /ext/fetch/23_response.js | |
parent | 0bc286ab47d82496b90efb429e16efccc10e5f2d (diff) |
cleanup(web, fetch): dedupe minesniff / "extract a MIME type" algorithm (#14044)
Closes #14002
Diffstat (limited to 'ext/fetch/23_response.js')
-rw-r--r-- | ext/fetch/23_response.js | 37 |
1 files changed, 2 insertions, 35 deletions
diff --git a/ext/fetch/23_response.js b/ext/fetch/23_response.js index 03f8c276b..f1f6fe1dd 100644 --- a/ext/fetch/23_response.js +++ b/ext/fetch/23_response.js @@ -18,7 +18,7 @@ const { HTTP_TAB_OR_SPACE, regexMatcher } = window.__bootstrap.infra; const { extractBody, mixinBody } = window.__bootstrap.fetchBody; const { getLocationHref } = window.__bootstrap.location; - const mimesniff = window.__bootstrap.mimesniff; + const { extractMimeType } = window.__bootstrap.mimesniff; const { URL } = window.__bootstrap.url; const { getDecodeSplitHeader, @@ -30,9 +30,6 @@ const { ArrayPrototypeMap, ArrayPrototypePush, - MapPrototypeHas, - MapPrototypeGet, - MapPrototypeSet, ObjectPrototypeIsPrototypeOf, RangeError, RegExp, @@ -162,41 +159,11 @@ class Response { get [_mimeType]() { - let charset = null; - let essence = null; - let mimeType = null; const values = getDecodeSplitHeader( headerListFromHeaders(this[_headers]), "Content-Type", ); - if (values === null) return null; - for (const value of values) { - const temporaryMimeType = mimesniff.parseMimeType(value); - if ( - temporaryMimeType === null || - mimesniff.essence(temporaryMimeType) == "*/*" - ) { - continue; - } - mimeType = temporaryMimeType; - if (mimesniff.essence(mimeType) !== essence) { - charset = null; - const newCharset = MapPrototypeGet(mimeType.parameters, "charset"); - if (newCharset !== undefined) { - charset = newCharset; - } - essence = mimesniff.essence(mimeType); - } else { - if ( - MapPrototypeHas(mimeType.parameters, "charset") === null && - charset !== null - ) { - MapPrototypeSet(mimeType.parameters, "charset", charset); - } - } - } - if (mimeType === null) return null; - return mimeType; + return extractMimeType(values); } get [_body]() { return this[_response].body; |