2021-01-11 12:13:41 -05:00
|
|
|
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
|
2021-04-18 19:00:13 -04:00
|
|
|
|
|
|
|
// @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-18 19:00:13 -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-18 19:00:13 -04:00
|
|
|
/// <reference path="./lib.deno_fetch.d.ts" />
|
|
|
|
/// <reference lib="esnext" />
|
2021-02-04 17:18:32 -05:00
|
|
|
"use strict";
|
2020-07-19 13:49:44 -04:00
|
|
|
|
|
|
|
((window) => {
|
2021-04-18 19:00:13 -04:00
|
|
|
const webidl = window.__bootstrap.webidl;
|
|
|
|
const {
|
2021-04-20 08:47:22 -04:00
|
|
|
HTTP_TAB_OR_SPACE_PREFIX_RE,
|
|
|
|
HTTP_TAB_OR_SPACE_SUFFIX_RE,
|
2021-04-18 19:00:13 -04:00
|
|
|
HTTP_WHITESPACE_PREFIX_RE,
|
|
|
|
HTTP_WHITESPACE_SUFFIX_RE,
|
|
|
|
HTTP_TOKEN_CODE_POINT_RE,
|
|
|
|
byteLowerCase,
|
2021-04-20 08:47:22 -04:00
|
|
|
collectSequenceOfCodepoints,
|
|
|
|
collectHttpQuotedString,
|
2021-04-18 19:00:13 -04:00
|
|
|
} = window.__bootstrap.infra;
|
2021-07-06 05:32:59 -04:00
|
|
|
const {
|
|
|
|
ArrayIsArray,
|
|
|
|
ArrayPrototypeMap,
|
|
|
|
ArrayPrototypePush,
|
|
|
|
ArrayPrototypeSort,
|
|
|
|
ArrayPrototypeJoin,
|
|
|
|
ArrayPrototypeSplice,
|
|
|
|
ArrayPrototypeFilter,
|
|
|
|
ObjectKeys,
|
|
|
|
ObjectEntries,
|
|
|
|
RegExpPrototypeTest,
|
|
|
|
Symbol,
|
|
|
|
SymbolFor,
|
|
|
|
SymbolIterator,
|
|
|
|
SymbolToStringTag,
|
|
|
|
StringPrototypeReplaceAll,
|
|
|
|
StringPrototypeIncludes,
|
|
|
|
TypeError,
|
|
|
|
} = window.__bootstrap.primordials;
|
2020-07-19 13:49:44 -04:00
|
|
|
|
2021-04-18 19:00:13 -04:00
|
|
|
const _headerList = Symbol("header list");
|
|
|
|
const _iterableHeaders = Symbol("iterable headers");
|
|
|
|
const _guard = Symbol("guard");
|
2020-07-19 13:49:44 -04:00
|
|
|
|
2021-04-18 19:00:13 -04:00
|
|
|
/**
|
|
|
|
* @typedef Header
|
|
|
|
* @type {[string, string]}
|
|
|
|
*/
|
2020-07-19 13:49:44 -04:00
|
|
|
|
2021-04-18 19:00:13 -04:00
|
|
|
/**
|
|
|
|
* @typedef HeaderList
|
|
|
|
* @type {Header[]}
|
|
|
|
*/
|
2020-07-19 13:49:44 -04:00
|
|
|
|
2021-04-18 19:00:13 -04:00
|
|
|
/**
|
2021-04-28 10:08:51 -04:00
|
|
|
* @param {string} potentialValue
|
2021-04-18 19:00:13 -04:00
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
function normalizeHeaderValue(potentialValue) {
|
2021-07-06 05:32:59 -04:00
|
|
|
potentialValue = StringPrototypeReplaceAll(
|
|
|
|
potentialValue,
|
|
|
|
HTTP_WHITESPACE_PREFIX_RE,
|
|
|
|
"",
|
|
|
|
);
|
|
|
|
potentialValue = StringPrototypeReplaceAll(
|
|
|
|
potentialValue,
|
|
|
|
HTTP_WHITESPACE_SUFFIX_RE,
|
|
|
|
"",
|
|
|
|
);
|
2021-04-18 19:00:13 -04:00
|
|
|
return potentialValue;
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
2021-04-18 19:00:13 -04:00
|
|
|
/**
|
|
|
|
* @param {Headers} headers
|
|
|
|
* @param {HeadersInit} object
|
|
|
|
*/
|
|
|
|
function fillHeaders(headers, object) {
|
2021-07-06 05:32:59 -04:00
|
|
|
if (ArrayIsArray(object)) {
|
2021-04-18 19:00:13 -04:00
|
|
|
for (const header of object) {
|
|
|
|
if (header.length !== 2) {
|
|
|
|
throw new TypeError(
|
|
|
|
`Invalid header. Length must be 2, but is ${header.length}`,
|
|
|
|
);
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
2021-04-18 19:00:13 -04:00
|
|
|
appendHeader(headers, header[0], header[1]);
|
|
|
|
}
|
|
|
|
} else {
|
2021-07-06 05:32:59 -04:00
|
|
|
for (const key of ObjectKeys(object)) {
|
2021-04-18 19:00:13 -04:00
|
|
|
appendHeader(headers, key, object[key]);
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-18 19:00:13 -04:00
|
|
|
/**
|
|
|
|
* https://fetch.spec.whatwg.org/#concept-headers-append
|
|
|
|
* @param {Headers} headers
|
2021-04-28 10:08:51 -04:00
|
|
|
* @param {string} name
|
|
|
|
* @param {string} value
|
2021-04-18 19:00:13 -04:00
|
|
|
*/
|
|
|
|
function appendHeader(headers, name, value) {
|
|
|
|
// 1.
|
|
|
|
value = normalizeHeaderValue(value);
|
|
|
|
|
|
|
|
// 2.
|
2021-07-06 05:32:59 -04:00
|
|
|
if (!RegExpPrototypeTest(HTTP_TOKEN_CODE_POINT_RE, name)) {
|
2021-04-18 19:00:13 -04:00
|
|
|
throw new TypeError("Header name is not valid.");
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
2021-04-18 19:00:13 -04:00
|
|
|
if (
|
2021-07-06 05:32:59 -04:00
|
|
|
StringPrototypeIncludes(value, "\x00") ||
|
|
|
|
StringPrototypeIncludes(value, "\x0A") ||
|
|
|
|
StringPrototypeIncludes(value, "\x0D")
|
2021-04-18 19:00:13 -04:00
|
|
|
) {
|
|
|
|
throw new TypeError("Header value is not valid.");
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
2021-04-18 19:00:13 -04:00
|
|
|
// 3.
|
|
|
|
if (headers[_guard] == "immutable") {
|
|
|
|
throw new TypeError("Headers are immutable.");
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
2021-04-18 19:00:13 -04:00
|
|
|
// 7.
|
|
|
|
const list = headers[_headerList];
|
2021-06-15 10:37:05 -04:00
|
|
|
name = byteLowerCase(name);
|
2021-07-06 05:32:59 -04:00
|
|
|
ArrayPrototypePush(list, [name, value]);
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
2021-04-18 19:00:13 -04:00
|
|
|
/**
|
2021-04-20 08:47:22 -04:00
|
|
|
* https://fetch.spec.whatwg.org/#concept-header-list-get
|
2021-04-18 19:00:13 -04:00
|
|
|
* @param {HeaderList} list
|
|
|
|
* @param {string} name
|
|
|
|
*/
|
|
|
|
function getHeader(list, name) {
|
|
|
|
const lowercaseName = byteLowerCase(name);
|
2021-07-06 05:32:59 -04:00
|
|
|
const entries = ArrayPrototypeMap(
|
|
|
|
ArrayPrototypeFilter(list, (entry) => entry[0] === lowercaseName),
|
|
|
|
(entry) => entry[1],
|
|
|
|
);
|
2021-04-18 19:00:13 -04:00
|
|
|
if (entries.length === 0) {
|
|
|
|
return null;
|
|
|
|
} else {
|
2021-07-06 05:32:59 -04:00
|
|
|
return ArrayPrototypeJoin(entries, "\x2C\x20");
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-20 08:47:22 -04:00
|
|
|
/**
|
|
|
|
* https://fetch.spec.whatwg.org/#concept-header-list-get-decode-split
|
|
|
|
* @param {HeaderList} list
|
|
|
|
* @param {string} name
|
|
|
|
* @returns {string[] | null}
|
|
|
|
*/
|
|
|
|
function getDecodeSplitHeader(list, name) {
|
|
|
|
const initialValue = getHeader(list, name);
|
|
|
|
if (initialValue === null) return null;
|
|
|
|
const input = initialValue;
|
|
|
|
let position = 0;
|
|
|
|
const values = [];
|
|
|
|
let value = "";
|
|
|
|
while (position < initialValue.length) {
|
|
|
|
// 7.1. collect up to " or ,
|
|
|
|
const res = collectSequenceOfCodepoints(
|
|
|
|
initialValue,
|
|
|
|
position,
|
|
|
|
(c) => c !== "\u0022" && c !== "\u002C",
|
|
|
|
);
|
|
|
|
value += res.result;
|
|
|
|
position = res.position;
|
|
|
|
|
|
|
|
if (position < initialValue.length) {
|
|
|
|
if (input[position] === "\u0022") {
|
|
|
|
const res = collectHttpQuotedString(input, position, false);
|
|
|
|
value += res.result;
|
|
|
|
position = res.position;
|
|
|
|
if (position < initialValue.length) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (input[position] !== "\u002C") throw new TypeError("Unreachable");
|
|
|
|
position += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-06 05:32:59 -04:00
|
|
|
value = StringPrototypeReplaceAll(value, HTTP_TAB_OR_SPACE_PREFIX_RE, "");
|
|
|
|
value = StringPrototypeReplaceAll(value, HTTP_TAB_OR_SPACE_SUFFIX_RE, "");
|
2021-04-20 08:47:22 -04:00
|
|
|
|
2021-07-06 05:32:59 -04:00
|
|
|
ArrayPrototypePush(values, value);
|
2021-04-20 08:47:22 -04:00
|
|
|
value = "";
|
|
|
|
}
|
|
|
|
return values;
|
|
|
|
}
|
|
|
|
|
2021-04-18 19:00:13 -04:00
|
|
|
class Headers {
|
|
|
|
/** @type {HeaderList} */
|
|
|
|
[_headerList] = [];
|
2021-04-20 08:47:22 -04:00
|
|
|
/** @type {"immutable" | "request" | "request-no-cors" | "response" | "none"} */
|
2021-04-18 19:00:13 -04:00
|
|
|
[_guard];
|
|
|
|
|
|
|
|
get [_iterableHeaders]() {
|
|
|
|
const list = this[_headerList];
|
|
|
|
|
2021-05-10 04:01:51 -04:00
|
|
|
// The order of steps are not similar to the ones suggested by the
|
|
|
|
// spec but produce the same result.
|
|
|
|
const headers = {};
|
|
|
|
const cookies = [];
|
2021-04-18 19:00:13 -04:00
|
|
|
for (const entry of list) {
|
2021-06-15 10:37:05 -04:00
|
|
|
const name = entry[0];
|
2021-05-10 04:01:51 -04:00
|
|
|
const value = entry[1];
|
|
|
|
if (value === null) throw new TypeError("Unreachable");
|
|
|
|
// The following if statement is not spec compliant.
|
|
|
|
// `set-cookie` is the only header that can not be concatentated,
|
|
|
|
// so must be given to the user as multiple headers.
|
2021-04-18 19:00:13 -04:00
|
|
|
// The else block of the if statement is spec compliant again.
|
2021-05-10 04:01:51 -04:00
|
|
|
if (name === "set-cookie") {
|
2021-07-06 05:32:59 -04:00
|
|
|
ArrayPrototypePush(cookies, [name, value]);
|
2021-04-18 19:00:13 -04:00
|
|
|
} else {
|
2021-05-10 04:01:51 -04:00
|
|
|
// The following code has the same behaviour as getHeader()
|
|
|
|
// at the end of loop. But it avoids looping through the entire
|
|
|
|
// list to combine multiple values with same header name. It
|
|
|
|
// instead gradually combines them as they are found.
|
|
|
|
let header = headers[name];
|
|
|
|
if (header && header.length > 0) {
|
|
|
|
header += "\x2C\x20" + value;
|
|
|
|
} else {
|
|
|
|
header = value;
|
|
|
|
}
|
|
|
|
headers[name] = header;
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
}
|
2021-05-10 04:01:51 -04:00
|
|
|
|
2021-07-06 05:32:59 -04:00
|
|
|
return ArrayPrototypeSort(
|
|
|
|
[...ObjectEntries(headers), ...cookies],
|
|
|
|
(a, b) => {
|
|
|
|
const akey = a[0];
|
|
|
|
const bkey = b[0];
|
|
|
|
if (akey > bkey) return 1;
|
|
|
|
if (akey < bkey) return -1;
|
|
|
|
return 0;
|
|
|
|
},
|
|
|
|
);
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
2021-04-18 19:00:13 -04:00
|
|
|
/** @param {HeadersInit} [init] */
|
|
|
|
constructor(init = undefined) {
|
2021-08-20 23:07:30 -04:00
|
|
|
const prefix = "Failed to construct 'Headers'";
|
2021-04-18 19:00:13 -04:00
|
|
|
if (init !== undefined) {
|
|
|
|
init = webidl.converters["HeadersInit"](init, {
|
|
|
|
prefix,
|
|
|
|
context: "Argument 1",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
this[webidl.brand] = webidl.brand;
|
|
|
|
this[_guard] = "none";
|
|
|
|
if (init !== undefined) {
|
|
|
|
fillHeaders(this, init);
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-18 19:00:13 -04:00
|
|
|
/**
|
2021-04-28 10:08:51 -04:00
|
|
|
* @param {string} name
|
|
|
|
* @param {string} value
|
2021-04-18 19:00:13 -04:00
|
|
|
*/
|
2020-07-19 13:49:44 -04:00
|
|
|
append(name, value) {
|
2021-04-18 19:00:13 -04:00
|
|
|
webidl.assertBranded(this, Headers);
|
|
|
|
const prefix = "Failed to execute 'append' on 'Headers'";
|
|
|
|
webidl.requiredArguments(arguments.length, 2, { prefix });
|
|
|
|
name = webidl.converters["ByteString"](name, {
|
|
|
|
prefix,
|
|
|
|
context: "Argument 1",
|
|
|
|
});
|
|
|
|
value = webidl.converters["ByteString"](value, {
|
|
|
|
prefix,
|
|
|
|
context: "Argument 2",
|
|
|
|
});
|
|
|
|
appendHeader(this, name, value);
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
2021-04-18 19:00:13 -04:00
|
|
|
/**
|
2021-04-28 10:08:51 -04:00
|
|
|
* @param {string} name
|
2021-04-18 19:00:13 -04:00
|
|
|
*/
|
2020-07-19 13:49:44 -04:00
|
|
|
delete(name) {
|
2021-04-18 19:00:13 -04:00
|
|
|
const prefix = "Failed to execute 'delete' on 'Headers'";
|
|
|
|
webidl.requiredArguments(arguments.length, 1, { prefix });
|
|
|
|
name = webidl.converters["ByteString"](name, {
|
|
|
|
prefix,
|
|
|
|
context: "Argument 1",
|
|
|
|
});
|
|
|
|
|
2021-07-06 05:32:59 -04:00
|
|
|
if (!RegExpPrototypeTest(HTTP_TOKEN_CODE_POINT_RE, name)) {
|
2021-04-18 19:00:13 -04:00
|
|
|
throw new TypeError("Header name is not valid.");
|
|
|
|
}
|
|
|
|
if (this[_guard] == "immutable") {
|
|
|
|
throw new TypeError("Headers are immutable.");
|
|
|
|
}
|
|
|
|
|
|
|
|
const list = this[_headerList];
|
2021-06-15 10:37:05 -04:00
|
|
|
name = byteLowerCase(name);
|
2021-04-18 19:00:13 -04:00
|
|
|
for (let i = 0; i < list.length; i++) {
|
2021-06-15 10:37:05 -04:00
|
|
|
if (list[i][0] === name) {
|
2021-07-06 05:32:59 -04:00
|
|
|
ArrayPrototypeSplice(list, i, 1);
|
2021-04-18 19:00:13 -04:00
|
|
|
i--;
|
|
|
|
}
|
|
|
|
}
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
2021-04-18 19:00:13 -04:00
|
|
|
/**
|
2021-04-28 10:08:51 -04:00
|
|
|
* @param {string} name
|
2021-04-18 19:00:13 -04:00
|
|
|
*/
|
2020-07-19 13:49:44 -04:00
|
|
|
get(name) {
|
2021-04-18 19:00:13 -04:00
|
|
|
const prefix = "Failed to execute 'get' on 'Headers'";
|
|
|
|
webidl.requiredArguments(arguments.length, 1, { prefix });
|
|
|
|
name = webidl.converters["ByteString"](name, {
|
|
|
|
prefix,
|
|
|
|
context: "Argument 1",
|
|
|
|
});
|
|
|
|
|
2021-07-06 05:32:59 -04:00
|
|
|
if (!RegExpPrototypeTest(HTTP_TOKEN_CODE_POINT_RE, name)) {
|
2021-04-18 19:00:13 -04:00
|
|
|
throw new TypeError("Header name is not valid.");
|
|
|
|
}
|
|
|
|
|
|
|
|
const list = this[_headerList];
|
|
|
|
return getHeader(list, name);
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
2021-04-18 19:00:13 -04:00
|
|
|
/**
|
2021-04-28 10:08:51 -04:00
|
|
|
* @param {string} name
|
2021-04-18 19:00:13 -04:00
|
|
|
*/
|
2020-07-19 13:49:44 -04:00
|
|
|
has(name) {
|
2021-04-18 19:00:13 -04:00
|
|
|
const prefix = "Failed to execute 'has' on 'Headers'";
|
|
|
|
webidl.requiredArguments(arguments.length, 1, { prefix });
|
|
|
|
name = webidl.converters["ByteString"](name, {
|
|
|
|
prefix,
|
|
|
|
context: "Argument 1",
|
|
|
|
});
|
|
|
|
|
2021-07-06 05:32:59 -04:00
|
|
|
if (!RegExpPrototypeTest(HTTP_TOKEN_CODE_POINT_RE, name)) {
|
2021-04-18 19:00:13 -04:00
|
|
|
throw new TypeError("Header name is not valid.");
|
|
|
|
}
|
|
|
|
|
|
|
|
const list = this[_headerList];
|
2021-06-15 10:37:05 -04:00
|
|
|
name = byteLowerCase(name);
|
2021-04-18 19:00:13 -04:00
|
|
|
for (let i = 0; i < list.length; i++) {
|
2021-06-15 10:37:05 -04:00
|
|
|
if (list[i][0] === name) {
|
2021-04-18 19:00:13 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
2021-04-18 19:00:13 -04:00
|
|
|
/**
|
2021-04-28 10:08:51 -04:00
|
|
|
* @param {string} name
|
|
|
|
* @param {string} value
|
2021-04-18 19:00:13 -04:00
|
|
|
*/
|
2020-07-19 13:49:44 -04:00
|
|
|
set(name, value) {
|
2021-04-18 19:00:13 -04:00
|
|
|
webidl.assertBranded(this, Headers);
|
|
|
|
const prefix = "Failed to execute 'set' on 'Headers'";
|
|
|
|
webidl.requiredArguments(arguments.length, 2, { prefix });
|
|
|
|
name = webidl.converters["ByteString"](name, {
|
|
|
|
prefix,
|
|
|
|
context: "Argument 1",
|
|
|
|
});
|
|
|
|
value = webidl.converters["ByteString"](value, {
|
|
|
|
prefix,
|
|
|
|
context: "Argument 2",
|
|
|
|
});
|
|
|
|
|
|
|
|
value = normalizeHeaderValue(value);
|
|
|
|
|
|
|
|
// 2.
|
2021-07-06 05:32:59 -04:00
|
|
|
if (!RegExpPrototypeTest(HTTP_TOKEN_CODE_POINT_RE, name)) {
|
2021-04-18 19:00:13 -04:00
|
|
|
throw new TypeError("Header name is not valid.");
|
|
|
|
}
|
|
|
|
if (
|
2021-07-06 05:32:59 -04:00
|
|
|
StringPrototypeIncludes(value, "\x00") ||
|
|
|
|
StringPrototypeIncludes(value, "\x0A") ||
|
|
|
|
StringPrototypeIncludes(value, "\x0D")
|
2021-04-18 19:00:13 -04:00
|
|
|
) {
|
|
|
|
throw new TypeError("Header value is not valid.");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this[_guard] == "immutable") {
|
|
|
|
throw new TypeError("Headers are immutable.");
|
|
|
|
}
|
|
|
|
|
|
|
|
const list = this[_headerList];
|
2021-06-15 10:37:05 -04:00
|
|
|
name = byteLowerCase(name);
|
2021-04-18 19:00:13 -04:00
|
|
|
let added = false;
|
|
|
|
for (let i = 0; i < list.length; i++) {
|
2021-06-15 10:37:05 -04:00
|
|
|
if (list[i][0] === name) {
|
2021-04-18 19:00:13 -04:00
|
|
|
if (!added) {
|
|
|
|
list[i][1] = value;
|
|
|
|
added = true;
|
|
|
|
} else {
|
2021-07-06 05:32:59 -04:00
|
|
|
ArrayPrototypeSplice(list, i, 1);
|
2021-04-18 19:00:13 -04:00
|
|
|
i--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!added) {
|
2021-07-06 05:32:59 -04:00
|
|
|
ArrayPrototypePush(list, [name, value]);
|
2021-04-18 19:00:13 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-06 05:32:59 -04:00
|
|
|
[SymbolFor("Deno.privateCustomInspect")](inspect) {
|
2021-04-18 19:00:13 -04:00
|
|
|
const headers = {};
|
|
|
|
for (const header of this) {
|
|
|
|
headers[header[0]] = header[1];
|
|
|
|
}
|
|
|
|
return `Headers ${inspect(headers)}`;
|
2020-07-19 13:49:44 -04:00
|
|
|
}
|
|
|
|
|
2021-07-06 05:32:59 -04:00
|
|
|
get [SymbolToStringTag]() {
|
2020-07-19 13:49:44 -04:00
|
|
|
return "Headers";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-18 19:00:13 -04:00
|
|
|
webidl.mixinPairIterable("Headers", Headers, _iterableHeaders, 0, 1);
|
|
|
|
|
2021-06-07 04:04:10 -04:00
|
|
|
webidl.configurePrototype(Headers);
|
|
|
|
|
2021-04-18 19:00:13 -04:00
|
|
|
webidl.converters["HeadersInit"] = (V, opts) => {
|
|
|
|
// Union for (sequence<sequence<ByteString>> or record<ByteString, ByteString>)
|
2021-06-16 12:40:35 -04:00
|
|
|
if (webidl.type(V) === "Object" && V !== null) {
|
2021-07-06 05:32:59 -04:00
|
|
|
if (V[SymbolIterator] !== undefined) {
|
2021-04-18 19:00:13 -04:00
|
|
|
return webidl.converters["sequence<sequence<ByteString>>"](V, opts);
|
|
|
|
}
|
|
|
|
return webidl.converters["record<ByteString, ByteString>"](V, opts);
|
|
|
|
}
|
|
|
|
throw webidl.makeException(
|
|
|
|
TypeError,
|
|
|
|
"The provided value is not of type '(sequence<sequence<ByteString>> or record<ByteString, ByteString>)'",
|
|
|
|
opts,
|
|
|
|
);
|
|
|
|
};
|
|
|
|
webidl.converters["Headers"] = webidl.createInterfaceConverter(
|
|
|
|
"Headers",
|
|
|
|
Headers,
|
|
|
|
);
|
2020-07-19 13:49:44 -04:00
|
|
|
|
2021-04-20 08:47:22 -04:00
|
|
|
/**
|
|
|
|
* @param {HeaderList} list
|
|
|
|
* @param {"immutable" | "request" | "request-no-cors" | "response" | "none"} guard
|
|
|
|
* @returns {Headers}
|
|
|
|
*/
|
|
|
|
function headersFromHeaderList(list, guard) {
|
|
|
|
const headers = webidl.createBranded(Headers);
|
|
|
|
headers[_headerList] = list;
|
|
|
|
headers[_guard] = guard;
|
|
|
|
return headers;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {Headers}
|
|
|
|
* @returns {HeaderList}
|
|
|
|
*/
|
|
|
|
function headerListFromHeaders(headers) {
|
|
|
|
return headers[_headerList];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {Headers}
|
|
|
|
* @returns {"immutable" | "request" | "request-no-cors" | "response" | "none"}
|
|
|
|
*/
|
|
|
|
function guardFromHeaders(headers) {
|
|
|
|
return headers[_guard];
|
|
|
|
}
|
|
|
|
|
2020-07-19 13:49:44 -04:00
|
|
|
window.__bootstrap.headers = {
|
|
|
|
Headers,
|
2021-04-20 08:47:22 -04:00
|
|
|
headersFromHeaderList,
|
|
|
|
headerListFromHeaders,
|
|
|
|
fillHeaders,
|
|
|
|
getDecodeSplitHeader,
|
|
|
|
guardFromHeaders,
|
2020-07-19 13:49:44 -04:00
|
|
|
};
|
|
|
|
})(this);
|