Spaces:
Running
Running
File size: 41,822 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 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 |
function _array_like_to_array(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
return arr2;
}
function _array_with_holes(arr) {
if (Array.isArray(arr)) return arr;
}
function _class_call_check(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
function _defineProperties(target, props) {
for(var i = 0; i < props.length; i++){
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
function _create_class(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
return Constructor;
}
function _instanceof(left, right) {
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
return !!right[Symbol.hasInstance](left);
} else {
return left instanceof right;
}
}
function _iterable_to_array_limit(arr, i) {
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
if (_i == null) return;
var _arr = [];
var _n = true;
var _d = false;
var _s, _e;
try {
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
_arr.push(_s.value);
if (i && _arr.length === i) break;
}
} catch (err) {
_d = true;
_e = err;
} finally{
try {
if (!_n && _i["return"] != null) _i["return"]();
} finally{
if (_d) throw _e;
}
}
return _arr;
}
function _non_iterable_rest() {
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _sliced_to_array(arr, i) {
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
}
function _unsupported_iterable_to_array(o, minLen) {
if (!o) return;
if (typeof o === "string") return _array_like_to_array(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(n);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
}
function _ts_generator(thisArg, body) {
var f, y, t, g, _ = {
label: 0,
sent: function() {
if (t[0] & 1) throw t[1];
return t[1];
},
trys: [],
ops: []
};
return g = {
next: verb(0),
"throw": verb(1),
"return": verb(2)
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
return this;
}), g;
function verb(n) {
return function(v) {
return step([
n,
v
]);
};
}
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while(_)try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [
op[0] & 2,
t.value
];
switch(op[0]){
case 0:
case 1:
t = op;
break;
case 4:
_.label++;
return {
value: op[1],
done: false
};
case 5:
_.label++;
y = op[1];
op = [
0
];
continue;
case 7:
op = _.ops.pop();
_.trys.pop();
continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
_ = 0;
continue;
}
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
_.label = op[1];
break;
}
if (op[0] === 6 && _.label < t[1]) {
_.label = t[1];
t = op;
break;
}
if (t && _.label < t[2]) {
_.label = t[2];
_.ops.push(op);
break;
}
if (t[2]) _.ops.pop();
_.trys.pop();
continue;
}
op = body.call(thisArg, _);
} catch (e) {
op = [
6,
e
];
y = 0;
} finally{
f = t = 0;
}
if (op[0] & 5) throw op[1];
return {
value: op[0] ? op[1] : void 0,
done: true
};
}
}
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 = function(cb, mod) {
return function __require() {
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = {
exports: {}
}).exports, mod), mod.exports;
};
};
var __export = function(target, all) {
for(var name in all)__defProp(target, name, {
get: all[name],
enumerable: true
});
};
var __copyProps = function(to, from, except, desc) {
if (from && typeof from === "object" || typeof from === "function") {
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
try {
var _loop = function() {
var key = _step.value;
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
get: function() {
return from[key];
},
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
});
};
for(var _iterator = __getOwnPropNames(from)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally{
try {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally{
if (_didIteratorError) {
throw _iteratorError;
}
}
}
}
return to;
};
var __toESM = function(mod, isNodeMode, target) {
return 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);
};
var __toCommonJS = function(mod) {
return __copyProps(__defProp({}, "__esModule", {
value: true
}), mod);
};
// node_modules/set-cookie-parser/lib/set-cookie.js
var require_set_cookie = __commonJS({
"node_modules/set-cookie-parser/lib/set-cookie.js": function(exports, module2) {
"use strict";
var isNonEmptyString = function isNonEmptyString(str) {
return typeof str === "string" && !!str.trim();
};
var parseString = 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: name,
value: 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;
};
var parseNameValuePair = 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: name,
value: value
};
};
var parse = 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);
}
};
var splitCookiesString2 = 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;
};
var defaultParseOptions = {
decodeValues: true,
map: false,
silent: false
};
module2.exports = parse;
module2.exports.parse = parse;
module2.exports.parseString = parseString;
module2.exports.splitCookiesString = splitCookiesString2;
}
});
// src/index.ts
var src_exports = {};
__export(src_exports, {
Headers: function() {
return Headers;
},
flattenHeadersList: function() {
return flattenHeadersList;
},
flattenHeadersObject: function() {
return flattenHeadersObject;
},
getRawHeaders: function() {
return getRawHeaders;
},
headersToList: function() {
return headersToList;
},
headersToObject: function() {
return headersToObject;
},
headersToString: function() {
return headersToString;
},
listToHeaders: function() {
return listToHeaders;
},
objectToHeaders: function() {
return objectToHeaders;
},
reduceHeadersObject: function() {
return reduceHeadersObject;
},
stringToHeaders: function() {
return stringToHeaders;
}
});
module.exports = __toCommonJS(src_exports);
// 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("(^[".concat(charCodesToRemove.join(""), "]|$[").concat(charCodesToRemove.join(""), "])"), "g");
function normalizeHeaderValue(value) {
var 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(var i = 0; i < value.length; i++){
var 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(var i = 0; i < value.length; i++){
var 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 = /*#__PURE__*/ function() {
"use strict";
function _Headers(init) {
var _this = this;
_class_call_check(this, _Headers);
var _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 = init) === null || _init === void 0 ? void 0 : _init.constructor.name) || _instanceof(init, _Headers) || typeof globalThis.Headers !== "undefined" && _instanceof(init, globalThis.Headers)) {
var initialHeaders = init;
initialHeaders.forEach(function(value, name) {
_this.append(name, value);
}, this);
} else if (Array.isArray(init)) {
init.forEach(function(param) {
var _param = _sliced_to_array(param, 2), name = _param[0], value = _param[1];
_this.append(name, Array.isArray(value) ? value.join(HEADER_VALUE_DELIMITER) : value);
});
} else if (init) {
Object.getOwnPropertyNames(init).forEach(function(name) {
var value = init[name];
_this.append(name, Array.isArray(value) ? value.join(HEADER_VALUE_DELIMITER) : value);
});
}
}
_create_class(_Headers, [
{
key: (_a = NORMALIZED_HEADERS, _b = RAW_HEADER_NAMES, _c = Symbol.toStringTag, Symbol.iterator),
value: function value() {
return this.entries();
}
},
{
key: "keys",
value: function keys() {
var _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _step_value, name, err;
return _ts_generator(this, function(_state) {
switch(_state.label){
case 0:
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
_state.label = 1;
case 1:
_state.trys.push([
1,
6,
7,
8
]);
_iterator = this.entries()[Symbol.iterator]();
_state.label = 2;
case 2:
if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
3,
5
];
_step_value = _sliced_to_array(_step.value, 1), name = _step_value[0];
return [
4,
name
];
case 3:
_state.sent();
_state.label = 4;
case 4:
_iteratorNormalCompletion = true;
return [
3,
2
];
case 5:
return [
3,
8
];
case 6:
err = _state.sent();
_didIteratorError = true;
_iteratorError = err;
return [
3,
8
];
case 7:
try {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally{
if (_didIteratorError) {
throw _iteratorError;
}
}
return [
7
];
case 8:
return [
2
];
}
});
}
},
{
key: "values",
value: function values() {
var _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _step_value, value, err;
return _ts_generator(this, function(_state) {
switch(_state.label){
case 0:
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
_state.label = 1;
case 1:
_state.trys.push([
1,
6,
7,
8
]);
_iterator = this.entries()[Symbol.iterator]();
_state.label = 2;
case 2:
if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
3,
5
];
_step_value = _sliced_to_array(_step.value, 2), value = _step_value[1];
return [
4,
value
];
case 3:
_state.sent();
_state.label = 4;
case 4:
_iteratorNormalCompletion = true;
return [
3,
2
];
case 5:
return [
3,
8
];
case 6:
err = _state.sent();
_didIteratorError = true;
_iteratorError = err;
return [
3,
8
];
case 7:
try {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally{
if (_didIteratorError) {
throw _iteratorError;
}
}
return [
7
];
case 8:
return [
2
];
}
});
}
},
{
key: "entries",
value: function entries() {
var sortedKeys, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, name, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, value, err, err;
return _ts_generator(this, function(_state) {
switch(_state.label){
case 0:
sortedKeys = Object.keys(this[NORMALIZED_HEADERS]).sort(function(a, b) {
return a.localeCompare(b);
});
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
_state.label = 1;
case 1:
_state.trys.push([
1,
15,
16,
17
]);
_iterator = sortedKeys[Symbol.iterator]();
_state.label = 2;
case 2:
if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
3,
14
];
name = _step.value;
if (!(name === "set-cookie")) return [
3,
11
];
_iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
_state.label = 3;
case 3:
_state.trys.push([
3,
8,
9,
10
]);
_iterator1 = this.getSetCookie()[Symbol.iterator]();
_state.label = 4;
case 4:
if (!!(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done)) return [
3,
7
];
value = _step1.value;
return [
4,
[
name,
value
]
];
case 5:
_state.sent();
_state.label = 6;
case 6:
_iteratorNormalCompletion1 = true;
return [
3,
4
];
case 7:
return [
3,
10
];
case 8:
err = _state.sent();
_didIteratorError1 = true;
_iteratorError1 = err;
return [
3,
10
];
case 9:
try {
if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
_iterator1.return();
}
} finally{
if (_didIteratorError1) {
throw _iteratorError1;
}
}
return [
7
];
case 10:
return [
3,
13
];
case 11:
return [
4,
[
name,
this.get(name)
]
];
case 12:
_state.sent();
_state.label = 13;
case 13:
_iteratorNormalCompletion = true;
return [
3,
2
];
case 14:
return [
3,
17
];
case 15:
err = _state.sent();
_didIteratorError = true;
_iteratorError = err;
return [
3,
17
];
case 16:
try {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally{
if (_didIteratorError) {
throw _iteratorError;
}
}
return [
7
];
case 17:
return [
2
];
}
});
}
},
{
/**
* Returns a boolean stating whether a `Headers` object contains a certain header.
*/ key: "has",
value: function has(name) {
if (!isValidHeaderName(name)) {
throw new TypeError('Invalid header name "'.concat(name, '"'));
}
return this[NORMALIZED_HEADERS].hasOwnProperty(normalizeHeaderName(name));
}
},
{
/**
* Returns a `ByteString` sequence of all the values of a header with a given name.
*/ key: "get",
value: function get(name) {
if (!isValidHeaderName(name)) {
throw TypeError('Invalid header name "'.concat(name, '"'));
}
var _this_NORMALIZED_HEADERS_normalizeHeaderName;
return (_this_NORMALIZED_HEADERS_normalizeHeaderName = this[NORMALIZED_HEADERS][normalizeHeaderName(name)]) !== null && _this_NORMALIZED_HEADERS_normalizeHeaderName !== void 0 ? _this_NORMALIZED_HEADERS_normalizeHeaderName : null;
}
},
{
/**
* Sets a new value for an existing header inside a `Headers` object, or adds the header if it does not already exist.
*/ key: "set",
value: function set(name, value) {
if (!isValidHeaderName(name) || !isValidHeaderValue(value)) {
return;
}
var normalizedName = normalizeHeaderName(name);
var 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.
*/ key: "append",
value: function append(name, value) {
if (!isValidHeaderName(name) || !isValidHeaderValue(value)) {
return;
}
var normalizedName = normalizeHeaderName(name);
var normalizedValue = normalizeHeaderValue(value);
var resolvedValue = this.has(normalizedName) ? "".concat(this.get(normalizedName), ", ").concat(normalizedValue) : normalizedValue;
this.set(name, resolvedValue);
}
},
{
/**
* Deletes a header from the `Headers` object.
*/ key: "delete",
value: function _delete(name) {
if (!isValidHeaderName(name)) {
return;
}
if (!this.has(name)) {
return;
}
var 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.
*/ key: "forEach",
value: function forEach(callback, thisArg) {
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
try {
for(var _iterator = this.entries()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
var _step_value = _sliced_to_array(_step.value, 2), name = _step_value[0], value = _step_value[1];
callback.call(thisArg, value, name, this);
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally{
try {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally{
if (_didIteratorError) {
throw _iteratorError;
}
}
}
}
},
{
/**
* Returns an array containing the values
* of all Set-Cookie headers associated
* with a response
*/ key: "getSetCookie",
value: function getSetCookie() {
var setCookieHeader = this.get("set-cookie");
if (setCookieHeader === null) {
return [];
}
if (setCookieHeader === "") {
return [
""
];
}
return (0, import_set_cookie_parser.splitCookiesString)(setCookieHeader);
}
}
]);
return _Headers;
}();
// src/getRawHeaders.ts
function getRawHeaders(headers) {
var rawHeaders = {};
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
try {
for(var _iterator = headers.entries()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
var _step_value = _sliced_to_array(_step.value, 2), name = _step_value[0], value = _step_value[1];
rawHeaders[headers[RAW_HEADER_NAMES].get(name)] = value;
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally{
try {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally{
if (_didIteratorError) {
throw _iteratorError;
}
}
}
return rawHeaders;
}
// src/transformers/headersToList.ts
function headersToList(headers) {
var headersList = [];
headers.forEach(function(value, name) {
var resolvedValue = value.includes(",") ? value.split(",").map(function(value2) {
return value2.trim();
}) : value;
headersList.push([
name,
resolvedValue
]);
});
return headersList;
}
// src/transformers/headersToString.ts
function headersToString(headers) {
var list = headersToList(headers);
var lines = list.map(function(param) {
var _param = _sliced_to_array(param, 2), name = _param[0], value = _param[1];
var values = [].concat(value);
return "".concat(name, ": ").concat(values.join(", "));
});
return lines.join("\r\n");
}
// src/transformers/headersToObject.ts
var singleValueHeaders = [
"user-agent"
];
function headersToObject(headers) {
var headersObject = {};
headers.forEach(function(value, name) {
var isMultiValue = !singleValueHeaders.includes(name.toLowerCase()) && value.includes(",");
headersObject[name] = isMultiValue ? value.split(",").map(function(s) {
return s.trim();
}) : value;
});
return headersObject;
}
// src/transformers/stringToHeaders.ts
function stringToHeaders(str) {
var lines = str.trim().split(/[\r\n]+/);
return lines.reduce(function(headers, line) {
if (line.trim() === "") {
return headers;
}
var parts = line.split(": ");
var name = parts.shift();
var value = parts.join(": ");
headers.append(name, value);
return headers;
}, new Headers());
}
// src/transformers/listToHeaders.ts
function listToHeaders(list) {
var headers = new Headers();
list.forEach(function(param) {
var _param = _sliced_to_array(param, 2), name = _param[0], value = _param[1];
var values = [].concat(value);
values.forEach(function(value2) {
headers.append(name, value2);
});
});
return headers;
}
// src/transformers/reduceHeadersObject.ts
function reduceHeadersObject(headers, reducer, initialState) {
return Object.keys(headers).reduce(function(nextHeaders, name) {
return reducer(nextHeaders, name, headers[name]);
}, initialState);
}
// src/transformers/objectToHeaders.ts
function objectToHeaders(headersObject) {
return reduceHeadersObject(headersObject, function(headers, name, value) {
var values = [].concat(value).filter(Boolean);
values.forEach(function(value2) {
headers.append(name, value2);
});
return headers;
}, new Headers());
}
// src/transformers/flattenHeadersList.ts
function flattenHeadersList(list) {
return list.map(function(param) {
var _param = _sliced_to_array(param, 2), name = _param[0], values = _param[1];
return [
name,
[].concat(values).join(", ")
];
});
}
// src/transformers/flattenHeadersObject.ts
function flattenHeadersObject(headersObject) {
return reduceHeadersObject(headersObject, function(headers, name, value) {
headers[name] = [].concat(value).join(", ");
return headers;
}, {});
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
Headers: Headers,
flattenHeadersList: flattenHeadersList,
flattenHeadersObject: flattenHeadersObject,
getRawHeaders: getRawHeaders,
headersToList: headersToList,
headersToObject: headersToObject,
headersToString: headersToString,
listToHeaders: listToHeaders,
objectToHeaders: objectToHeaders,
reduceHeadersObject: reduceHeadersObject,
stringToHeaders: stringToHeaders
});
//# sourceMappingURL=index.js.map |