Spaces:
Running
Running
File size: 16,562 Bytes
d4b85c0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 |
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __commonJS = (cb, mod) => function __require() {
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
// node_modules/set-cookie-parser/lib/set-cookie.js
var require_set_cookie = __commonJS({
"node_modules/set-cookie-parser/lib/set-cookie.js"(exports, module) {
"use strict";
var defaultParseOptions = {
decodeValues: true,
map: false,
silent: false
};
function isNonEmptyString(str) {
return typeof str === "string" && !!str.trim();
}
function parseString(setCookieValue, options) {
var parts = setCookieValue.split(";").filter(isNonEmptyString);
var nameValuePairStr = parts.shift();
var parsed = parseNameValuePair(nameValuePairStr);
var name = parsed.name;
var value = parsed.value;
options = options ? Object.assign({}, defaultParseOptions, options) : defaultParseOptions;
try {
value = options.decodeValues ? decodeURIComponent(value) : value;
} catch (e) {
console.error(
"set-cookie-parser encountered an error while decoding a cookie with value '" + value + "'. Set options.decodeValues to false to disable this feature.",
e
);
}
var cookie = {
name,
value
};
parts.forEach(function(part) {
var sides = part.split("=");
var key = sides.shift().trimLeft().toLowerCase();
var value2 = sides.join("=");
if (key === "expires") {
cookie.expires = new Date(value2);
} else if (key === "max-age") {
cookie.maxAge = parseInt(value2, 10);
} else if (key === "secure") {
cookie.secure = true;
} else if (key === "httponly") {
cookie.httpOnly = true;
} else if (key === "samesite") {
cookie.sameSite = value2;
} else {
cookie[key] = value2;
}
});
return cookie;
}
function parseNameValuePair(nameValuePairStr) {
var name = "";
var value = "";
var nameValueArr = nameValuePairStr.split("=");
if (nameValueArr.length > 1) {
name = nameValueArr.shift();
value = nameValueArr.join("=");
} else {
value = nameValuePairStr;
}
return { name, value };
}
function parse(input, options) {
options = options ? Object.assign({}, defaultParseOptions, options) : defaultParseOptions;
if (!input) {
if (!options.map) {
return [];
} else {
return {};
}
}
if (input.headers) {
if (typeof input.headers.getSetCookie === "function") {
input = input.headers.getSetCookie();
} else if (input.headers["set-cookie"]) {
input = input.headers["set-cookie"];
} else {
var sch = input.headers[Object.keys(input.headers).find(function(key) {
return key.toLowerCase() === "set-cookie";
})];
if (!sch && input.headers.cookie && !options.silent) {
console.warn(
"Warning: set-cookie-parser appears to have been called on a request object. It is designed to parse Set-Cookie headers from responses, not Cookie headers from requests. Set the option {silent: true} to suppress this warning."
);
}
input = sch;
}
}
if (!Array.isArray(input)) {
input = [input];
}
options = options ? Object.assign({}, defaultParseOptions, options) : defaultParseOptions;
if (!options.map) {
return input.filter(isNonEmptyString).map(function(str) {
return parseString(str, options);
});
} else {
var cookies = {};
return input.filter(isNonEmptyString).reduce(function(cookies2, str) {
var cookie = parseString(str, options);
cookies2[cookie.name] = cookie;
return cookies2;
}, cookies);
}
}
function splitCookiesString2(cookiesString) {
if (Array.isArray(cookiesString)) {
return cookiesString;
}
if (typeof cookiesString !== "string") {
return [];
}
var cookiesStrings = [];
var pos = 0;
var start;
var ch;
var lastComma;
var nextStart;
var cookiesSeparatorFound;
function skipWhitespace() {
while (pos < cookiesString.length && /\s/.test(cookiesString.charAt(pos))) {
pos += 1;
}
return pos < cookiesString.length;
}
function notSpecialChar() {
ch = cookiesString.charAt(pos);
return ch !== "=" && ch !== ";" && ch !== ",";
}
while (pos < cookiesString.length) {
start = pos;
cookiesSeparatorFound = false;
while (skipWhitespace()) {
ch = cookiesString.charAt(pos);
if (ch === ",") {
lastComma = pos;
pos += 1;
skipWhitespace();
nextStart = pos;
while (pos < cookiesString.length && notSpecialChar()) {
pos += 1;
}
if (pos < cookiesString.length && cookiesString.charAt(pos) === "=") {
cookiesSeparatorFound = true;
pos = nextStart;
cookiesStrings.push(cookiesString.substring(start, lastComma));
start = pos;
} else {
pos = lastComma + 1;
}
} else {
pos += 1;
}
}
if (!cookiesSeparatorFound || pos >= cookiesString.length) {
cookiesStrings.push(cookiesString.substring(start, cookiesString.length));
}
}
return cookiesStrings;
}
module.exports = parse;
module.exports.parse = parse;
module.exports.parseString = parseString;
module.exports.splitCookiesString = splitCookiesString2;
}
});
// src/Headers.ts
var import_set_cookie_parser = __toESM(require_set_cookie());
// src/utils/normalizeHeaderName.ts
var HEADERS_INVALID_CHARACTERS = /[^a-z0-9\-#$%&'*+.^_`|~]/i;
function normalizeHeaderName(name) {
if (HEADERS_INVALID_CHARACTERS.test(name) || name.trim() === "") {
throw new TypeError("Invalid character in header field name");
}
return name.trim().toLowerCase();
}
// src/utils/normalizeHeaderValue.ts
var charCodesToRemove = [
String.fromCharCode(10),
String.fromCharCode(13),
String.fromCharCode(9),
String.fromCharCode(32)
];
var HEADER_VALUE_REMOVE_REGEXP = new RegExp(
`(^[${charCodesToRemove.join("")}]|$[${charCodesToRemove.join("")}])`,
"g"
);
function normalizeHeaderValue(value) {
const nextValue = value.replace(HEADER_VALUE_REMOVE_REGEXP, "");
return nextValue;
}
// src/utils/isValidHeaderName.ts
function isValidHeaderName(value) {
if (typeof value !== "string") {
return false;
}
if (value.length === 0) {
return false;
}
for (let i = 0; i < value.length; i++) {
const character = value.charCodeAt(i);
if (character > 127 || !isToken(character)) {
return false;
}
}
return true;
}
function isToken(value) {
return ![
127,
32,
"(",
")",
"<",
">",
"@",
",",
";",
":",
"\\",
'"',
"/",
"[",
"]",
"?",
"=",
"{",
"}"
].includes(value);
}
// src/utils/isValidHeaderValue.ts
function isValidHeaderValue(value) {
if (typeof value !== "string") {
return false;
}
if (value.trim() !== value) {
return false;
}
for (let i = 0; i < value.length; i++) {
const character = value.charCodeAt(i);
if (
// NUL.
character === 0 || // HTTP newline bytes.
character === 10 || character === 13
) {
return false;
}
}
return true;
}
// src/Headers.ts
var NORMALIZED_HEADERS = Symbol("normalizedHeaders");
var RAW_HEADER_NAMES = Symbol("rawHeaderNames");
var HEADER_VALUE_DELIMITER = ", ";
var _a, _b, _c;
var Headers = class _Headers {
constructor(init) {
// Normalized header {"name":"a, b"} storage.
this[_a] = {};
// Keeps the mapping between the raw header name
// and the normalized header name to ease the lookup.
this[_b] = /* @__PURE__ */ new Map();
this[_c] = "Headers";
if (["Headers", "HeadersPolyfill"].includes(init?.constructor.name) || init instanceof _Headers || typeof globalThis.Headers !== "undefined" && init instanceof globalThis.Headers) {
const initialHeaders = init;
initialHeaders.forEach((value, name) => {
this.append(name, value);
}, this);
} else if (Array.isArray(init)) {
init.forEach(([name, value]) => {
this.append(
name,
Array.isArray(value) ? value.join(HEADER_VALUE_DELIMITER) : value
);
});
} else if (init) {
Object.getOwnPropertyNames(init).forEach((name) => {
const value = init[name];
this.append(
name,
Array.isArray(value) ? value.join(HEADER_VALUE_DELIMITER) : value
);
});
}
}
[(_a = NORMALIZED_HEADERS, _b = RAW_HEADER_NAMES, _c = Symbol.toStringTag, Symbol.iterator)]() {
return this.entries();
}
*keys() {
for (const [name] of this.entries()) {
yield name;
}
}
*values() {
for (const [, value] of this.entries()) {
yield value;
}
}
*entries() {
let sortedKeys = Object.keys(this[NORMALIZED_HEADERS]).sort(
(a, b) => a.localeCompare(b)
);
for (const name of sortedKeys) {
if (name === "set-cookie") {
for (const value of this.getSetCookie()) {
yield [name, value];
}
} else {
yield [name, this.get(name)];
}
}
}
/**
* Returns a boolean stating whether a `Headers` object contains a certain header.
*/
has(name) {
if (!isValidHeaderName(name)) {
throw new TypeError(`Invalid header name "${name}"`);
}
return this[NORMALIZED_HEADERS].hasOwnProperty(normalizeHeaderName(name));
}
/**
* Returns a `ByteString` sequence of all the values of a header with a given name.
*/
get(name) {
if (!isValidHeaderName(name)) {
throw TypeError(`Invalid header name "${name}"`);
}
return this[NORMALIZED_HEADERS][normalizeHeaderName(name)] ?? null;
}
/**
* Sets a new value for an existing header inside a `Headers` object, or adds the header if it does not already exist.
*/
set(name, value) {
if (!isValidHeaderName(name) || !isValidHeaderValue(value)) {
return;
}
const normalizedName = normalizeHeaderName(name);
const normalizedValue = normalizeHeaderValue(value);
this[NORMALIZED_HEADERS][normalizedName] = normalizeHeaderValue(normalizedValue);
this[RAW_HEADER_NAMES].set(normalizedName, name);
}
/**
* Appends a new value onto an existing header inside a `Headers` object, or adds the header if it does not already exist.
*/
append(name, value) {
if (!isValidHeaderName(name) || !isValidHeaderValue(value)) {
return;
}
const normalizedName = normalizeHeaderName(name);
const normalizedValue = normalizeHeaderValue(value);
let resolvedValue = this.has(normalizedName) ? `${this.get(normalizedName)}, ${normalizedValue}` : normalizedValue;
this.set(name, resolvedValue);
}
/**
* Deletes a header from the `Headers` object.
*/
delete(name) {
if (!isValidHeaderName(name)) {
return;
}
if (!this.has(name)) {
return;
}
const normalizedName = normalizeHeaderName(name);
delete this[NORMALIZED_HEADERS][normalizedName];
this[RAW_HEADER_NAMES].delete(normalizedName);
}
/**
* Traverses the `Headers` object,
* calling the given callback for each header.
*/
forEach(callback, thisArg) {
for (const [name, value] of this.entries()) {
callback.call(thisArg, value, name, this);
}
}
/**
* Returns an array containing the values
* of all Set-Cookie headers associated
* with a response
*/
getSetCookie() {
const setCookieHeader = this.get("set-cookie");
if (setCookieHeader === null) {
return [];
}
if (setCookieHeader === "") {
return [""];
}
return (0, import_set_cookie_parser.splitCookiesString)(setCookieHeader);
}
};
// src/getRawHeaders.ts
function getRawHeaders(headers) {
const rawHeaders = {};
for (const [name, value] of headers.entries()) {
rawHeaders[headers[RAW_HEADER_NAMES].get(name)] = value;
}
return rawHeaders;
}
// src/transformers/headersToList.ts
function headersToList(headers) {
const headersList = [];
headers.forEach((value, name) => {
const resolvedValue = value.includes(",") ? value.split(",").map((value2) => value2.trim()) : value;
headersList.push([name, resolvedValue]);
});
return headersList;
}
// src/transformers/headersToString.ts
function headersToString(headers) {
const list = headersToList(headers);
const lines = list.map(([name, value]) => {
const values = [].concat(value);
return `${name}: ${values.join(", ")}`;
});
return lines.join("\r\n");
}
// src/transformers/headersToObject.ts
var singleValueHeaders = ["user-agent"];
function headersToObject(headers) {
const headersObject = {};
headers.forEach((value, name) => {
const isMultiValue = !singleValueHeaders.includes(name.toLowerCase()) && value.includes(",");
headersObject[name] = isMultiValue ? value.split(",").map((s) => s.trim()) : value;
});
return headersObject;
}
// src/transformers/stringToHeaders.ts
function stringToHeaders(str) {
const lines = str.trim().split(/[\r\n]+/);
return lines.reduce((headers, line) => {
if (line.trim() === "") {
return headers;
}
const parts = line.split(": ");
const name = parts.shift();
const value = parts.join(": ");
headers.append(name, value);
return headers;
}, new Headers());
}
// src/transformers/listToHeaders.ts
function listToHeaders(list) {
const headers = new Headers();
list.forEach(([name, value]) => {
const values = [].concat(value);
values.forEach((value2) => {
headers.append(name, value2);
});
});
return headers;
}
// src/transformers/reduceHeadersObject.ts
function reduceHeadersObject(headers, reducer, initialState) {
return Object.keys(headers).reduce((nextHeaders, name) => {
return reducer(nextHeaders, name, headers[name]);
}, initialState);
}
// src/transformers/objectToHeaders.ts
function objectToHeaders(headersObject) {
return reduceHeadersObject(
headersObject,
(headers, name, value) => {
const values = [].concat(value).filter(Boolean);
values.forEach((value2) => {
headers.append(name, value2);
});
return headers;
},
new Headers()
);
}
// src/transformers/flattenHeadersList.ts
function flattenHeadersList(list) {
return list.map(([name, values]) => {
return [name, [].concat(values).join(", ")];
});
}
// src/transformers/flattenHeadersObject.ts
function flattenHeadersObject(headersObject) {
return reduceHeadersObject(
headersObject,
(headers, name, value) => {
headers[name] = [].concat(value).join(", ");
return headers;
},
{}
);
}
export {
Headers,
flattenHeadersList,
flattenHeadersObject,
getRawHeaders,
headersToList,
headersToObject,
headersToString,
listToHeaders,
objectToHeaders,
reduceHeadersObject,
stringToHeaders
};
//# sourceMappingURL=index.mjs.map |