mirror of
https://github.com/denoland/deno.git
synced 2025-08-03 02:22:40 +00:00
cleanup(web, fetch): dedupe minesniff / "extract a MIME type" algorithm (#14044)
Closes #14002
This commit is contained in:
parent
0bc286ab47
commit
593801e265
4 changed files with 55 additions and 71 deletions
|
@ -18,7 +18,7 @@
|
|||
const { guardFromHeaders } = window.__bootstrap.headers;
|
||||
const { mixinBody, extractBody } = window.__bootstrap.fetchBody;
|
||||
const { getLocationHref } = window.__bootstrap.location;
|
||||
const mimesniff = window.__bootstrap.mimesniff;
|
||||
const { extractMimeType } = window.__bootstrap.mimesniff;
|
||||
const { blobFromObjectUrl } = window.__bootstrap.file;
|
||||
const {
|
||||
headersFromHeaderList,
|
||||
|
@ -32,9 +32,6 @@
|
|||
ArrayPrototypeMap,
|
||||
ArrayPrototypeSlice,
|
||||
ArrayPrototypeSplice,
|
||||
MapPrototypeHas,
|
||||
MapPrototypeGet,
|
||||
MapPrototypeSet,
|
||||
ObjectKeys,
|
||||
ObjectPrototypeIsPrototypeOf,
|
||||
RegExpPrototypeTest,
|
||||
|
@ -174,41 +171,11 @@
|
|||
/** @type {AbortSignal} */
|
||||
[_signal];
|
||||
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[_request].body;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue