2021-04-14 16:49:16 -04:00
|
|
|
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
|
|
|
|
|
|
|
|
// @ts-check
|
|
|
|
/// <reference path="../webidl/internal.d.ts" />
|
|
|
|
/// <reference path="../web/internal.d.ts" />
|
2021-06-10 09:26:10 -04:00
|
|
|
/// <reference path="../web/lib.deno_web.d.ts" />
|
2021-04-14 16:49:16 -04:00
|
|
|
/// <reference path="./internal.d.ts" />
|
2021-06-14 07:51:02 -04:00
|
|
|
/// <reference path="../web/06_streams_types.d.ts" />
|
2021-04-14 16:49:16 -04:00
|
|
|
/// <reference path="./lib.deno_fetch.d.ts" />
|
|
|
|
/// <reference lib="esnext" />
|
|
|
|
"use strict";
|
|
|
|
|
2021-06-05 17:10:07 -04:00
|
|
|
((window) => {
|
|
|
|
const core = window.Deno.core;
|
2021-04-14 16:49:16 -04:00
|
|
|
const webidl = globalThis.__bootstrap.webidl;
|
2021-06-22 08:06:37 -04:00
|
|
|
const { Blob, File } = globalThis.__bootstrap.file;
|
2021-07-06 05:32:59 -04:00
|
|
|
const {
|
|
|
|
ArrayPrototypeMap,
|
|
|
|
ArrayPrototypePush,
|
|
|
|
ArrayPrototypeSlice,
|
|
|
|
ArrayPrototypeSplice,
|
|
|
|
ArrayPrototypeFilter,
|
|
|
|
ArrayPrototypeForEach,
|
|
|
|
Map,
|
|
|
|
MapPrototypeGet,
|
|
|
|
MapPrototypeSet,
|
|
|
|
MathRandom,
|
|
|
|
Symbol,
|
|
|
|
StringFromCharCode,
|
|
|
|
StringPrototypeTrim,
|
|
|
|
StringPrototypeSlice,
|
|
|
|
StringPrototypeSplit,
|
|
|
|
StringPrototypeReplace,
|
|
|
|
StringPrototypeIndexOf,
|
|
|
|
StringPrototypePadStart,
|
|
|
|
StringPrototypeCodePointAt,
|
|
|
|
StringPrototypeReplaceAll,
|
|
|
|
TypeError,
|
|
|
|
TypedArrayPrototypeSubarray,
|
|
|
|
} = window.__bootstrap.primordials;
|
2021-04-14 16:49:16 -04:00
|
|
|
|
|
|
|
const entryList = Symbol("entry list");
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string} name
|
|
|
|
* @param {string | Blob} value
|
|
|
|
* @param {string | undefined} filename
|
|
|
|
* @returns {FormDataEntry}
|
|
|
|
*/
|
|
|
|
function createEntry(name, value, filename) {
|
|
|
|
if (value instanceof Blob && !(value instanceof File)) {
|
2021-06-22 08:06:37 -04:00
|
|
|
value = new File([value], "blob", { type: value.type });
|
2021-04-14 16:49:16 -04:00
|
|
|
}
|
|
|
|
if (value instanceof File && filename !== undefined) {
|
2021-06-22 08:06:37 -04:00
|
|
|
value = new File([value], filename, {
|
2021-04-14 16:49:16 -04:00
|
|
|
type: value.type,
|
|
|
|
lastModified: value.lastModified,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
name,
|
|
|
|
// @ts-expect-error because TS is not smart enough
|
|
|
|
value,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @typedef FormDataEntry
|
|
|
|
* @property {string} name
|
|
|
|
* @property {FormDataEntryValue} value
|
|
|
|
*/
|
|
|
|
|
|
|
|
class FormData {
|
|
|
|
/** @type {FormDataEntry[]} */
|
|
|
|
[entryList] = [];
|
|
|
|
|
|
|
|
/** @param {void} form */
|
|
|
|
constructor(form) {
|
|
|
|
if (form !== undefined) {
|
|
|
|
webidl.illegalConstructor();
|
|
|
|
}
|
|
|
|
this[webidl.brand] = webidl.brand;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-04-28 10:08:51 -04:00
|
|
|
* @param {string} name
|
|
|
|
* @param {string | Blob} valueOrBlobValue
|
2021-04-14 16:49:16 -04:00
|
|
|
* @param {string} [filename]
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
append(name, valueOrBlobValue, filename) {
|
|
|
|
webidl.assertBranded(this, FormData);
|
|
|
|
const prefix = "Failed to execute 'append' on 'FormData'";
|
|
|
|
webidl.requiredArguments(arguments.length, 2, { prefix });
|
|
|
|
|
|
|
|
name = webidl.converters["USVString"](name, {
|
|
|
|
prefix,
|
|
|
|
context: "Argument 1",
|
|
|
|
});
|
|
|
|
if (valueOrBlobValue instanceof Blob) {
|
|
|
|
valueOrBlobValue = webidl.converters["Blob"](valueOrBlobValue, {
|
|
|
|
prefix,
|
|
|
|
context: "Argument 2",
|
|
|
|
});
|
|
|
|
if (filename !== undefined) {
|
|
|
|
filename = webidl.converters["USVString"](filename, {
|
|
|
|
prefix,
|
|
|
|
context: "Argument 3",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
valueOrBlobValue = webidl.converters["USVString"](valueOrBlobValue, {
|
|
|
|
prefix,
|
|
|
|
context: "Argument 2",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
const entry = createEntry(name, valueOrBlobValue, filename);
|
|
|
|
|
2021-07-06 05:32:59 -04:00
|
|
|
ArrayPrototypePush(this[entryList], entry);
|
2021-04-14 16:49:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-04-28 10:08:51 -04:00
|
|
|
* @param {string} name
|
2021-04-14 16:49:16 -04:00
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
delete(name) {
|
|
|
|
webidl.assertBranded(this, FormData);
|
|
|
|
const prefix = "Failed to execute 'name' on 'FormData'";
|
|
|
|
webidl.requiredArguments(arguments.length, 1, { prefix });
|
|
|
|
|
|
|
|
name = webidl.converters["USVString"](name, {
|
|
|
|
prefix,
|
|
|
|
context: "Argument 1",
|
|
|
|
});
|
|
|
|
|
|
|
|
const list = this[entryList];
|
|
|
|
for (let i = 0; i < list.length; i++) {
|
|
|
|
if (list[i].name === name) {
|
2021-07-06 05:32:59 -04:00
|
|
|
ArrayPrototypeSplice(list, i, 1);
|
2021-04-14 16:49:16 -04:00
|
|
|
i--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-04-28 10:08:51 -04:00
|
|
|
* @param {string} name
|
2021-04-14 16:49:16 -04:00
|
|
|
* @returns {FormDataEntryValue | null}
|
|
|
|
*/
|
|
|
|
get(name) {
|
|
|
|
webidl.assertBranded(this, FormData);
|
|
|
|
const prefix = "Failed to execute 'get' on 'FormData'";
|
|
|
|
webidl.requiredArguments(arguments.length, 1, { prefix });
|
|
|
|
|
|
|
|
name = webidl.converters["USVString"](name, {
|
|
|
|
prefix,
|
|
|
|
context: "Argument 1",
|
|
|
|
});
|
|
|
|
|
|
|
|
for (const entry of this[entryList]) {
|
|
|
|
if (entry.name === name) return entry.value;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-04-28 10:08:51 -04:00
|
|
|
* @param {string} name
|
2021-04-14 16:49:16 -04:00
|
|
|
* @returns {FormDataEntryValue[]}
|
|
|
|
*/
|
|
|
|
getAll(name) {
|
|
|
|
webidl.assertBranded(this, FormData);
|
|
|
|
const prefix = "Failed to execute 'getAll' on 'FormData'";
|
|
|
|
webidl.requiredArguments(arguments.length, 1, { prefix });
|
|
|
|
|
|
|
|
name = webidl.converters["USVString"](name, {
|
|
|
|
prefix,
|
|
|
|
context: "Argument 1",
|
|
|
|
});
|
|
|
|
|
|
|
|
const returnList = [];
|
|
|
|
for (const entry of this[entryList]) {
|
2021-07-06 05:32:59 -04:00
|
|
|
if (entry.name === name) ArrayPrototypePush(returnList, entry.value);
|
2021-04-14 16:49:16 -04:00
|
|
|
}
|
|
|
|
return returnList;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-04-28 10:08:51 -04:00
|
|
|
* @param {string} name
|
2021-04-14 16:49:16 -04:00
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
has(name) {
|
|
|
|
webidl.assertBranded(this, FormData);
|
|
|
|
const prefix = "Failed to execute 'has' on 'FormData'";
|
|
|
|
webidl.requiredArguments(arguments.length, 1, { prefix });
|
|
|
|
|
|
|
|
name = webidl.converters["USVString"](name, {
|
|
|
|
prefix,
|
|
|
|
context: "Argument 1",
|
|
|
|
});
|
|
|
|
|
|
|
|
for (const entry of this[entryList]) {
|
|
|
|
if (entry.name === name) return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-04-28 10:08:51 -04:00
|
|
|
* @param {string} name
|
|
|
|
* @param {string | Blob} valueOrBlobValue
|
2021-04-14 16:49:16 -04:00
|
|
|
* @param {string} [filename]
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
set(name, valueOrBlobValue, filename) {
|
|
|
|
webidl.assertBranded(this, FormData);
|
|
|
|
const prefix = "Failed to execute 'set' on 'FormData'";
|
|
|
|
webidl.requiredArguments(arguments.length, 2, { prefix });
|
|
|
|
|
|
|
|
name = webidl.converters["USVString"](name, {
|
|
|
|
prefix,
|
|
|
|
context: "Argument 1",
|
|
|
|
});
|
|
|
|
if (valueOrBlobValue instanceof Blob) {
|
|
|
|
valueOrBlobValue = webidl.converters["Blob"](valueOrBlobValue, {
|
|
|
|
prefix,
|
|
|
|
context: "Argument 2",
|
|
|
|
});
|
|
|
|
if (filename !== undefined) {
|
|
|
|
filename = webidl.converters["USVString"](filename, {
|
|
|
|
prefix,
|
|
|
|
context: "Argument 3",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
valueOrBlobValue = webidl.converters["USVString"](valueOrBlobValue, {
|
|
|
|
prefix,
|
|
|
|
context: "Argument 2",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
const entry = createEntry(name, valueOrBlobValue, filename);
|
|
|
|
|
|
|
|
const list = this[entryList];
|
|
|
|
let added = false;
|
|
|
|
for (let i = 0; i < list.length; i++) {
|
|
|
|
if (list[i].name === name) {
|
|
|
|
if (!added) {
|
|
|
|
list[i] = entry;
|
|
|
|
added = true;
|
|
|
|
} else {
|
2021-07-06 05:32:59 -04:00
|
|
|
ArrayPrototypeSplice(list, i, 1);
|
2021-04-14 16:49:16 -04:00
|
|
|
i--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!added) {
|
2021-07-06 05:32:59 -04:00
|
|
|
ArrayPrototypePush(list, entry);
|
2021-04-14 16:49:16 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
webidl.mixinPairIterable("FormData", FormData, entryList, "name", "value");
|
|
|
|
|
2021-06-07 04:04:10 -04:00
|
|
|
webidl.configurePrototype(FormData);
|
|
|
|
|
2021-06-22 08:06:37 -04:00
|
|
|
const escape = (str, isFilename) =>
|
2021-07-06 05:32:59 -04:00
|
|
|
StringPrototypeReplace(
|
|
|
|
StringPrototypeReplace(
|
|
|
|
StringPrototypeReplace(
|
|
|
|
(isFilename ? str : StringPrototypeReplace(str, /\r?\n|\r/g, "\r\n")),
|
|
|
|
/\n/g,
|
|
|
|
"%0A",
|
|
|
|
),
|
|
|
|
/\r/g,
|
|
|
|
"%0D",
|
|
|
|
),
|
|
|
|
/"/g,
|
|
|
|
"%22",
|
|
|
|
);
|
2021-04-14 16:49:16 -04:00
|
|
|
|
2021-06-22 08:06:37 -04:00
|
|
|
/**
|
|
|
|
* convert FormData to a Blob synchronous without reading all of the files
|
|
|
|
* @param {globalThis.FormData} formData
|
|
|
|
*/
|
|
|
|
function formDataToBlob(formData) {
|
2021-07-06 05:32:59 -04:00
|
|
|
const boundary = StringPrototypePadStart(
|
|
|
|
StringPrototypeSlice(
|
|
|
|
StringPrototypeReplaceAll(`${MathRandom()}${MathRandom()}`, ".", ""),
|
|
|
|
-28,
|
|
|
|
),
|
|
|
|
32,
|
|
|
|
"-",
|
|
|
|
);
|
2021-06-22 08:06:37 -04:00
|
|
|
const chunks = [];
|
|
|
|
const prefix = `--${boundary}\r\nContent-Disposition: form-data; name="`;
|
|
|
|
|
|
|
|
for (const [name, value] of formData) {
|
|
|
|
if (typeof value === "string") {
|
2021-07-06 05:32:59 -04:00
|
|
|
ArrayPrototypePush(
|
|
|
|
chunks,
|
2021-06-22 08:06:37 -04:00
|
|
|
prefix + escape(name) + '"' + CRLF + CRLF +
|
2021-07-06 05:32:59 -04:00
|
|
|
StringPrototypeReplace(value, /\r(?!\n)|(?<!\r)\n/g, CRLF) + CRLF,
|
2021-06-22 08:06:37 -04:00
|
|
|
);
|
|
|
|
} else {
|
2021-07-06 05:32:59 -04:00
|
|
|
ArrayPrototypePush(
|
|
|
|
chunks,
|
2021-06-22 08:06:37 -04:00
|
|
|
prefix + escape(name) + `"; filename="${escape(value.name, true)}"` +
|
|
|
|
CRLF +
|
|
|
|
`Content-Type: ${value.type || "application/octet-stream"}\r\n\r\n`,
|
|
|
|
value,
|
|
|
|
CRLF,
|
|
|
|
);
|
2021-04-14 16:49:16 -04:00
|
|
|
}
|
2021-05-27 19:33:11 -04:00
|
|
|
}
|
2021-04-14 16:49:16 -04:00
|
|
|
|
2021-07-06 05:32:59 -04:00
|
|
|
ArrayPrototypePush(chunks, `--${boundary}--`);
|
2021-04-14 16:49:16 -04:00
|
|
|
|
2021-06-22 08:06:37 -04:00
|
|
|
return new Blob(chunks, {
|
|
|
|
type: "multipart/form-data; boundary=" + boundary,
|
|
|
|
});
|
2021-04-14 16:49:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string} value
|
|
|
|
* @returns {Map<string, string>}
|
|
|
|
*/
|
|
|
|
function parseContentDisposition(value) {
|
|
|
|
/** @type {Map<string, string>} */
|
|
|
|
const params = new Map();
|
|
|
|
// Forced to do so for some Map constructor param mismatch
|
2021-07-06 05:32:59 -04:00
|
|
|
ArrayPrototypeForEach(
|
|
|
|
ArrayPrototypeMap(
|
|
|
|
ArrayPrototypeFilter(
|
|
|
|
ArrayPrototypeMap(
|
|
|
|
ArrayPrototypeSlice(StringPrototypeSplit(value, ";"), 1),
|
|
|
|
(s) => StringPrototypeSplit(StringPrototypeTrim(s), "="),
|
|
|
|
),
|
|
|
|
(arr) => arr.length > 1,
|
|
|
|
),
|
|
|
|
([k, v]) => [k, StringPrototypeReplace(v, /^"([^"]*)"$/, "$1")],
|
|
|
|
),
|
|
|
|
([k, v]) => MapPrototypeSet(params, k, v),
|
|
|
|
);
|
|
|
|
|
2021-04-14 16:49:16 -04:00
|
|
|
return params;
|
|
|
|
}
|
|
|
|
|
2021-06-22 08:06:37 -04:00
|
|
|
const CRLF = "\r\n";
|
2021-07-06 05:32:59 -04:00
|
|
|
const LF = StringPrototypeCodePointAt(CRLF, 1);
|
|
|
|
const CR = StringPrototypeCodePointAt(CRLF, 0);
|
2021-04-14 16:49:16 -04:00
|
|
|
|
|
|
|
class MultipartParser {
|
|
|
|
/**
|
2021-04-28 10:08:51 -04:00
|
|
|
* @param {Uint8Array} body
|
|
|
|
* @param {string | undefined} boundary
|
2021-04-14 16:49:16 -04:00
|
|
|
*/
|
|
|
|
constructor(body, boundary) {
|
|
|
|
if (!boundary) {
|
|
|
|
throw new TypeError("multipart/form-data must provide a boundary");
|
|
|
|
}
|
|
|
|
|
|
|
|
this.boundary = `--${boundary}`;
|
|
|
|
this.body = body;
|
2021-06-05 17:10:07 -04:00
|
|
|
this.boundaryChars = core.encode(this.boundary);
|
2021-04-14 16:49:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string} headersText
|
|
|
|
* @returns {{ headers: Headers, disposition: Map<string, string> }}
|
|
|
|
*/
|
2021-05-27 19:33:11 -04:00
|
|
|
#parseHeaders(headersText) {
|
2021-04-14 16:49:16 -04:00
|
|
|
const headers = new Headers();
|
2021-07-06 05:32:59 -04:00
|
|
|
const rawHeaders = StringPrototypeSplit(headersText, "\r\n");
|
2021-04-14 16:49:16 -04:00
|
|
|
for (const rawHeader of rawHeaders) {
|
2021-07-06 05:32:59 -04:00
|
|
|
const sepIndex = StringPrototypeIndexOf(rawHeader, ":");
|
2021-04-14 16:49:16 -04:00
|
|
|
if (sepIndex < 0) {
|
|
|
|
continue; // Skip this header
|
|
|
|
}
|
2021-07-06 05:32:59 -04:00
|
|
|
const key = StringPrototypeSlice(rawHeader, 0, sepIndex);
|
|
|
|
const value = StringPrototypeSlice(rawHeader, sepIndex + 1);
|
2021-04-14 16:49:16 -04:00
|
|
|
headers.set(key, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
const disposition = parseContentDisposition(
|
|
|
|
headers.get("Content-Disposition") ?? "",
|
|
|
|
);
|
|
|
|
|
|
|
|
return { headers, disposition };
|
2021-05-27 19:33:11 -04:00
|
|
|
}
|
2021-04-14 16:49:16 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns {FormData}
|
|
|
|
*/
|
|
|
|
parse() {
|
2021-04-20 08:47:22 -04:00
|
|
|
// Body must be at least 2 boundaries + \r\n + -- on the last boundary.
|
|
|
|
if (this.body.length < (this.boundary.length * 2) + 4) {
|
|
|
|
throw new TypeError("Form data too short to be valid.");
|
|
|
|
}
|
|
|
|
|
2021-04-14 16:49:16 -04:00
|
|
|
const formData = new FormData();
|
|
|
|
let headerText = "";
|
|
|
|
let boundaryIndex = 0;
|
|
|
|
let state = 0;
|
|
|
|
let fileStart = 0;
|
|
|
|
|
|
|
|
for (let i = 0; i < this.body.length; i++) {
|
|
|
|
const byte = this.body[i];
|
|
|
|
const prevByte = this.body[i - 1];
|
|
|
|
const isNewLine = byte === LF && prevByte === CR;
|
|
|
|
|
|
|
|
if (state === 1 || state === 2 || state == 3) {
|
2021-07-06 05:32:59 -04:00
|
|
|
headerText += StringFromCharCode(byte);
|
2021-04-14 16:49:16 -04:00
|
|
|
}
|
|
|
|
if (state === 0 && isNewLine) {
|
|
|
|
state = 1;
|
|
|
|
} else if (state === 1 && isNewLine) {
|
|
|
|
state = 2;
|
|
|
|
const headersDone = this.body[i + 1] === CR &&
|
|
|
|
this.body[i + 2] === LF;
|
|
|
|
|
|
|
|
if (headersDone) {
|
|
|
|
state = 3;
|
|
|
|
}
|
|
|
|
} else if (state === 2 && isNewLine) {
|
|
|
|
state = 3;
|
|
|
|
} else if (state === 3 && isNewLine) {
|
|
|
|
state = 4;
|
|
|
|
fileStart = i + 1;
|
|
|
|
} else if (state === 4) {
|
|
|
|
if (this.boundaryChars[boundaryIndex] !== byte) {
|
|
|
|
boundaryIndex = 0;
|
|
|
|
} else {
|
|
|
|
boundaryIndex++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (boundaryIndex >= this.boundary.length) {
|
|
|
|
const { headers, disposition } = this.#parseHeaders(headerText);
|
2021-07-06 05:32:59 -04:00
|
|
|
const content = TypedArrayPrototypeSubarray(
|
|
|
|
this.body,
|
2021-04-14 16:49:16 -04:00
|
|
|
fileStart,
|
|
|
|
i - boundaryIndex - 1,
|
|
|
|
);
|
|
|
|
// https://fetch.spec.whatwg.org/#ref-for-dom-body-formdata
|
2021-07-06 05:32:59 -04:00
|
|
|
const filename = MapPrototypeGet(disposition, "filename");
|
|
|
|
const name = MapPrototypeGet(disposition, "name");
|
2021-04-14 16:49:16 -04:00
|
|
|
|
|
|
|
state = 5;
|
|
|
|
// Reset
|
|
|
|
boundaryIndex = 0;
|
|
|
|
headerText = "";
|
|
|
|
|
|
|
|
if (!name) {
|
|
|
|
continue; // Skip, unknown name
|
|
|
|
}
|
|
|
|
|
|
|
|
if (filename) {
|
|
|
|
const blob = new Blob([content], {
|
|
|
|
type: headers.get("Content-Type") || "application/octet-stream",
|
|
|
|
});
|
|
|
|
formData.append(name, blob, filename);
|
|
|
|
} else {
|
2021-06-05 17:10:07 -04:00
|
|
|
formData.append(name, core.decode(content));
|
2021-04-14 16:49:16 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (state === 5 && isNewLine) {
|
|
|
|
state = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return formData;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-04-28 10:08:51 -04:00
|
|
|
* @param {Uint8Array} body
|
2021-04-14 16:49:16 -04:00
|
|
|
* @param {string | undefined} boundary
|
|
|
|
* @returns {FormData}
|
|
|
|
*/
|
|
|
|
function parseFormData(body, boundary) {
|
|
|
|
const parser = new MultipartParser(body, boundary);
|
|
|
|
return parser.parse();
|
|
|
|
}
|
|
|
|
|
2021-04-20 08:47:22 -04:00
|
|
|
/**
|
|
|
|
* @param {FormDataEntry[]} entries
|
2021-04-28 10:08:51 -04:00
|
|
|
* @returns {FormData}
|
2021-04-20 08:47:22 -04:00
|
|
|
*/
|
|
|
|
function formDataFromEntries(entries) {
|
|
|
|
const fd = new FormData();
|
|
|
|
fd[entryList] = entries;
|
|
|
|
return fd;
|
|
|
|
}
|
|
|
|
|
|
|
|
webidl.converters["FormData"] = webidl
|
|
|
|
.createInterfaceConverter("FormData", FormData);
|
|
|
|
|
|
|
|
globalThis.__bootstrap.formData = {
|
|
|
|
FormData,
|
2021-06-22 08:06:37 -04:00
|
|
|
formDataToBlob,
|
2021-04-20 08:47:22 -04:00
|
|
|
parseFormData,
|
|
|
|
formDataFromEntries,
|
|
|
|
};
|
2021-04-14 16:49:16 -04:00
|
|
|
})(globalThis);
|