This commit is contained in:
2026-08-14 16:03:47 +01:00
parent fd53e3f4fb
commit dfdc3b2840
2463 changed files with 186456 additions and 111315 deletions
+188 -29
View File
@@ -1,4 +1,3 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -21,32 +20,199 @@ __export(accept_exports, {
parseAccept: () => parseAccept
});
module.exports = __toCommonJS(accept_exports);
const isWhitespace = (char) => char === 32 || char === 9 || char === 10 || char === 13;
const consumeWhitespace = (acceptHeader, startIndex) => {
while (startIndex < acceptHeader.length) {
if (!isWhitespace(acceptHeader.charCodeAt(startIndex))) {
break;
}
startIndex++;
}
return startIndex;
};
const ignoreTrailingWhitespace = (acceptHeader, startIndex) => {
while (startIndex > 0) {
if (!isWhitespace(acceptHeader.charCodeAt(startIndex - 1))) {
break;
}
startIndex--;
}
return startIndex;
};
const skipInvalidParam = (acceptHeader, startIndex) => {
while (startIndex < acceptHeader.length) {
const char = acceptHeader.charCodeAt(startIndex);
if (char === 59) {
return [startIndex + 1, true];
}
if (char === 44) {
return [startIndex + 1, false];
}
startIndex++;
}
return [startIndex, false];
};
const skipInvalidAcceptValue = (acceptHeader, startIndex) => {
let i = startIndex;
let inQuotes = false;
while (i < acceptHeader.length) {
const char = acceptHeader.charCodeAt(i);
if (inQuotes && char === 92) {
i++;
} else if (char === 34) {
inQuotes = !inQuotes;
} else if (!inQuotes && char === 44) {
return i + 1;
}
i++;
}
return i;
};
const getNextParam = (acceptHeader, startIndex) => {
startIndex = consumeWhitespace(acceptHeader, startIndex);
let i = startIndex;
let key;
let value;
let hasNext = false;
while (i < acceptHeader.length) {
const char = acceptHeader.charCodeAt(i);
if (char === 61) {
key = acceptHeader.slice(startIndex, ignoreTrailingWhitespace(acceptHeader, i));
i++;
break;
}
if (char === 59) {
return [i + 1, void 0, void 0, true];
}
if (char === 44) {
return [i + 1, void 0, void 0, false];
}
i++;
}
if (key === void 0) {
return [i, void 0, void 0, false];
}
i = consumeWhitespace(acceptHeader, i);
if (acceptHeader.charCodeAt(i) === 61) {
const skipResult = skipInvalidParam(acceptHeader, i + 1);
return [skipResult[0], key, void 0, skipResult[1]];
}
let inQuotes = false;
const paramStartIndex = i;
while (i < acceptHeader.length) {
const char = acceptHeader.charCodeAt(i);
if (inQuotes && char === 92) {
i++;
} else if (char === 34) {
if (inQuotes) {
let nextIndex = consumeWhitespace(acceptHeader, i + 1);
const nextChar = acceptHeader.charCodeAt(nextIndex);
if (nextIndex < acceptHeader.length && !(nextChar === 59 || nextChar === 44)) {
const skipResult = skipInvalidParam(acceptHeader, nextIndex);
return [skipResult[0], key, void 0, skipResult[1]];
}
value = acceptHeader.slice(paramStartIndex + 1, i);
if (value.includes("\\")) {
value = value.replace(/\\(.)/g, "$1");
}
if (nextChar === 44) {
return [nextIndex + 1, key, value, false];
}
if (nextChar === 59) {
hasNext = true;
nextIndex++;
}
i = nextIndex;
break;
}
inQuotes = true;
} else if (!inQuotes && (char === 59 || char === 44)) {
value = acceptHeader.slice(paramStartIndex, ignoreTrailingWhitespace(acceptHeader, i));
if (char === 59) {
hasNext = true;
}
i++;
break;
}
i++;
}
return [
i,
key,
value ?? acceptHeader.slice(paramStartIndex, ignoreTrailingWhitespace(acceptHeader, i)),
hasNext
];
};
const getNextAcceptValue = (acceptHeader, startIndex) => {
const accept = {
type: "",
params: {},
q: 1
};
startIndex = consumeWhitespace(acceptHeader, startIndex);
let i = startIndex;
while (i < acceptHeader.length) {
const char = acceptHeader.charCodeAt(i);
if (char === 59 || char === 44) {
accept.type = acceptHeader.slice(startIndex, ignoreTrailingWhitespace(acceptHeader, i));
i++;
if (char === 44) {
return [i, accept.type ? accept : void 0];
}
if (!accept.type) {
return [skipInvalidAcceptValue(acceptHeader, i), void 0];
}
break;
}
i++;
}
if (!accept.type) {
accept.type = acceptHeader.slice(
startIndex,
ignoreTrailingWhitespace(acceptHeader, acceptHeader.length)
);
return [acceptHeader.length, accept.type ? accept : void 0];
}
let param;
let value;
let hasNext;
while (i < acceptHeader.length) {
;
[i, param, value, hasNext] = getNextParam(acceptHeader, i);
if (param && value) {
accept.params[param] = value;
}
if (!hasNext) {
break;
}
}
return [i, accept];
};
const parseAccept = (acceptHeader) => {
if (!acceptHeader) {
return [];
}
const acceptValues = acceptHeader.split(",").map((value, index) => ({ value, index }));
return acceptValues.map(parseAcceptValue).filter((item) => Boolean(item)).sort(sortByQualityAndIndex).map(({ type, params, q }) => ({ type, params, q }));
};
const parseAcceptValueRegex = /;(?=(?:(?:[^"]*"){2})*[^"]*$)/;
const parseAcceptValue = ({ value, index }) => {
const parts = value.trim().split(parseAcceptValueRegex).map((s) => s.trim());
const type = parts[0];
if (!type) {
return null;
}
const params = parseParams(parts.slice(1));
const q = parseQuality(params.q);
return { type, params, q, index };
};
const parseParams = (paramParts) => {
return paramParts.reduce((acc, param) => {
const [key, val] = param.split("=").map((s) => s.trim());
if (key && val) {
acc[key] = val;
const values = [];
let i = 0;
let accept;
let requiresSort = false;
let lastAccept;
while (i < acceptHeader.length) {
;
[i, accept] = getNextAcceptValue(acceptHeader, i);
if (accept) {
accept.q = parseQuality(accept.params.q);
values.push(accept);
if (lastAccept && lastAccept.q < accept.q) {
requiresSort = true;
}
lastAccept = accept;
}
return acc;
}, {});
}
if (requiresSort) {
values.sort((a, b) => b.q - a.q);
}
return values;
};
const parseQuality = (qVal) => {
if (qVal === void 0) {
@@ -73,13 +239,6 @@ const parseQuality = (qVal) => {
}
return num;
};
const sortByQualityAndIndex = (a, b) => {
const qDiff = b.q - a.q;
if (qDiff !== 0) {
return qDiff;
}
return a.index - b.index;
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
parseAccept
-1
View File
@@ -1,4 +1,3 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
+3 -1
View File
@@ -1,4 +1,3 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -76,6 +75,9 @@ const handleParsingAllValues = (form, key, value) => {
}
};
const handleParsingNestedValues = (form, key, value) => {
if (/(?:^|\.)__proto__\./.test(key)) {
return;
}
let nestedForm = form;
const keys = key.split(".");
keys.forEach((key2, index) => {
-1
View File
@@ -1,4 +1,3 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
-1
View File
@@ -1,4 +1,3 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
+1 -2
View File
@@ -1,4 +1,3 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -21,7 +20,7 @@ __export(compress_exports, {
COMPRESSIBLE_CONTENT_TYPE_REGEX: () => COMPRESSIBLE_CONTENT_TYPE_REGEX
});
module.exports = __toCommonJS(compress_exports);
const COMPRESSIBLE_CONTENT_TYPE_REGEX = /^\s*(?:text\/(?!event-stream(?:[;\s]|$))[^;\s]+|application\/(?:javascript|json|xml|xml-dtd|ecmascript|dart|postscript|rtf|tar|toml|vnd\.dart|vnd\.ms-fontobject|vnd\.ms-opentype|wasm|x-httpd-php|x-javascript|x-ns-proxy-autoconfig|x-sh|x-tar|x-virtualbox-hdd|x-virtualbox-ova|x-virtualbox-ovf|x-virtualbox-vbox|x-virtualbox-vdi|x-virtualbox-vhd|x-virtualbox-vmdk|x-www-form-urlencoded)|font\/(?:otf|ttf)|image\/(?:bmp|vnd\.adobe\.photoshop|vnd\.microsoft\.icon|vnd\.ms-dds|x-icon|x-ms-bmp)|message\/rfc822|model\/gltf-binary|x-shader\/x-fragment|x-shader\/x-vertex|[^;\s]+?\+(?:json|text|xml|yaml))(?:[;\s]|$)/i;
const COMPRESSIBLE_CONTENT_TYPE_REGEX = /^\s*(?:text\/(?!event-stream(?:[;\s]|$))[^;\s]+|application\/(?:javascript|json|xml|xml-dtd|ecmascript|dart|msgpack|postscript|rtf|tar|toml|vnd\.dart|vnd\.ms-fontobject|vnd\.ms-opentype|vnd\.msgpack|wasm|x-httpd-php|x-javascript|x-msgpack|x-ns-proxy-autoconfig|x-sh|x-tar|x-virtualbox-hdd|x-virtualbox-ova|x-virtualbox-ovf|x-virtualbox-vbox|x-virtualbox-vdi|x-virtualbox-vhd|x-virtualbox-vmdk|x-www-form-urlencoded)|font\/(?:otf|ttf)|image\/(?:bmp|vnd\.adobe\.photoshop|vnd\.microsoft\.icon|vnd\.ms-dds|x-icon|x-ms-bmp)|message\/rfc822|model\/gltf-binary|x-shader\/x-fragment|x-shader\/x-vertex|[^;\s]+?\+(?:json|text|xml|yaml|msgpack))(?:[;\s]|$)/i;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
COMPRESSIBLE_CONTENT_TYPE_REGEX
-1
View File
@@ -1,4 +1,3 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
-1
View File
@@ -1,4 +1,3 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
+30 -10
View File
@@ -1,4 +1,3 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -49,23 +48,41 @@ const verifySignature = async (base64Signature, value, secret) => {
};
const validCookieNameRegEx = /^[\w!#$%&'*.^`|~+-]+$/;
const validCookieValueRegEx = /^[ !#-:<-[\]-~]*$/;
const trimCookieWhitespace = (value) => {
let start = 0;
let end = value.length;
while (start < end) {
const charCode = value.charCodeAt(start);
if (charCode !== 32 && charCode !== 9) {
break;
}
start++;
}
while (end > start) {
const charCode = value.charCodeAt(end - 1);
if (charCode !== 32 && charCode !== 9) {
break;
}
end--;
}
return start === 0 && end === value.length ? value : value.slice(start, end);
};
const parse = (cookie, name) => {
if (name && cookie.indexOf(name) === -1) {
return {};
}
const pairs = cookie.trim().split(";");
const parsedCookie = {};
for (let pairStr of pairs) {
pairStr = pairStr.trim();
const pairs = cookie.split(";");
const parsedCookie = /* @__PURE__ */ Object.create(null);
for (const pairStr of pairs) {
const valueStartPos = pairStr.indexOf("=");
if (valueStartPos === -1) {
continue;
}
const cookieName = pairStr.substring(0, valueStartPos).trim();
if (name && name !== cookieName || !validCookieNameRegEx.test(cookieName)) {
const cookieName = trimCookieWhitespace(pairStr.substring(0, valueStartPos));
if (name && name !== cookieName || !validCookieNameRegEx.test(cookieName) || cookieName in parsedCookie) {
continue;
}
let cookieValue = pairStr.substring(valueStartPos + 1).trim();
let cookieValue = trimCookieWhitespace(pairStr.substring(valueStartPos + 1));
if (cookieValue.startsWith('"') && cookieValue.endsWith('"')) {
cookieValue = cookieValue.slice(1, -1);
}
@@ -79,7 +96,7 @@ const parse = (cookie, name) => {
return parsedCookie;
};
const parseSigned = async (cookie, secret, name) => {
const parsedCookie = {};
const parsedCookie = /* @__PURE__ */ Object.create(null);
const secretKey = await getCryptoKey(secret);
for (const [key, value] of Object.entries(parse(cookie, name))) {
const signatureStartPos = value.lastIndexOf(".");
@@ -97,6 +114,9 @@ const parseSigned = async (cookie, secret, name) => {
return parsedCookie;
};
const _serialize = (name, value, opt = {}) => {
if (!validCookieNameRegEx.test(name)) {
throw new Error("Invalid cookie name");
}
let cookie = `${name}=${value}`;
if (name.startsWith("__Secure-") && !opt.secure) {
throw new Error("__Secure- Cookie must have Secure attributes");
@@ -112,7 +132,7 @@ const _serialize = (name, value, opt = {}) => {
throw new Error("__Host- Cookie must not have Domain attributes");
}
}
for (const key of ["domain", "path"]) {
for (const key of ["domain", "path", "sameSite", "priority"]) {
if (opt[key] && /[;\r\n]/.test(opt[key])) {
throw new Error(`${key} must not contain ";", "\\r", or "\\n"`);
}
-1
View File
@@ -1,4 +1,3 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
-1
View File
@@ -1,4 +1,3 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
+1 -2
View File
@@ -1,4 +1,3 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -43,7 +42,7 @@ const getFilePathWithoutDefaultDocument = (options) => {
return;
}
filename = filename.replace(/^\.?[\/\\]/, "");
filename = filename.replace(/\\/, "/");
filename = filename.replace(/\\/g, "/");
root = root.replace(/\/$/, "");
let path = root ? root + "/" + filename : filename;
path = path.replace(/^\.?\//, "");
-1
View File
@@ -1,4 +1,3 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
-1
View File
@@ -1,4 +1,3 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
-1
View File
@@ -1,4 +1,3 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
-1
View File
@@ -1,4 +1,3 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
+203 -15
View File
@@ -1,4 +1,3 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -18,12 +17,15 @@ var __copyProps = (to, from, except, desc) => {
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var ipaddr_exports = {};
__export(ipaddr_exports, {
INVALID_IP_ADDRESS_ERROR_CODE: () => INVALID_IP_ADDRESS_ERROR_CODE,
convertIPv4BinaryToString: () => convertIPv4BinaryToString,
convertIPv4MappedIPv6ToIPv4: () => convertIPv4MappedIPv6ToIPv4,
convertIPv4ToBinary: () => convertIPv4ToBinary,
convertIPv6BinaryToString: () => convertIPv6BinaryToString,
convertIPv6ToBinary: () => convertIPv6ToBinary,
distinctRemoteAddr: () => distinctRemoteAddr,
expandIPv6: () => expandIPv6
expandIPv6: () => expandIPv6,
isIPv4MappedIPv6: () => isIPv4MappedIPv6
});
module.exports = __toCommonJS(ipaddr_exports);
const expandIPv6 = (ipV6) => {
@@ -41,7 +43,9 @@ const expandIPv6 = (ipV6) => {
if (node !== "") {
sections[i] = node.padStart(4, "0");
} else {
sections[i + 1] === "" && sections.splice(i + 1, 1);
while (sections[i + 1] === "") {
sections.splice(i + 1, 1);
}
sections[i] = new Array(8 - sections.length + 1).fill("0000").join(":");
}
}
@@ -49,6 +53,16 @@ const expandIPv6 = (ipV6) => {
};
const IPV4_OCTET_PART = "(?:25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])";
const IPV4_REGEX = new RegExp(`^(?:${IPV4_OCTET_PART}\\.){3}${IPV4_OCTET_PART}$`);
const INVALID_IP_ADDRESS_ERROR_CODE = "ERR_INVALID_IP_ADDRESS";
const CHAR_CODE_0 = 48;
const CHAR_CODE_9 = 57;
const CHAR_CODE_A = 65;
const CHAR_CODE_F = 70;
const CHAR_CODE_a = 97;
const CHAR_CODE_f = 102;
const CHAR_CODE_DOT = 46;
const CHAR_CODE_COLON = 58;
const CHAR_CODE_PERCENT = 37;
const distinctRemoteAddr = (remoteAddr) => {
if (IPV4_REGEX.test(remoteAddr)) {
return "IPv4";
@@ -57,21 +71,187 @@ const distinctRemoteAddr = (remoteAddr) => {
return "IPv6";
}
};
const convertIPv4ToBinary = (ipv4) => {
const parts = ipv4.split(".");
const createInvalidIPAddressError = (message) => {
const error = new TypeError(message);
error.code = INVALID_IP_ADDRESS_ERROR_CODE;
return error;
};
const throwInvalidIPv4Address = (ipv4) => {
throw createInvalidIPAddressError(`Invalid IPv4 address: ${ipv4}`);
};
const throwInvalidIPv6Address = (ipv6) => {
throw createInvalidIPAddressError(`Invalid IPv6 address: ${ipv6}`);
};
const parseIPv4ToBinary = (ipv4, start, end, onInvalid) => {
let result = 0n;
for (let i = 0; i < 4; i++) {
result <<= 8n;
result += BigInt(parts[i]);
let octets = 0;
let octet = 0;
let digits = 0;
let firstDigit = 0;
for (let i = start; i <= end; i++) {
const code = i < end ? ipv4.charCodeAt(i) : CHAR_CODE_DOT;
if (code >= CHAR_CODE_0 && code <= CHAR_CODE_9) {
if (digits === 0) {
firstDigit = code;
} else if (firstDigit === CHAR_CODE_0) {
onInvalid();
}
octet = octet * 10 + code - CHAR_CODE_0;
if (octet > 255) {
onInvalid();
}
digits++;
continue;
}
if (code !== CHAR_CODE_DOT || digits === 0 || octets === 4) {
onInvalid();
}
result = (result << 8n) + BigInt(octet);
octets++;
octet = 0;
digits = 0;
}
if (octets !== 4) {
onInvalid();
}
return result;
};
const parseIPv6HexCode = (code) => {
if (code >= CHAR_CODE_0 && code <= CHAR_CODE_9) {
return code - CHAR_CODE_0;
}
if (code >= CHAR_CODE_A && code <= CHAR_CODE_F) {
return code - CHAR_CODE_A + 10;
}
if (code >= CHAR_CODE_a && code <= CHAR_CODE_f) {
return code - CHAR_CODE_a + 10;
}
return -1;
};
const isIPv6LinkLocal = (ipv6binary) => ipv6binary >> 118n === 0x3fan;
const convertIPv4ToBinary = (ipv4) => {
return parseIPv4ToBinary(ipv4, 0, ipv4.length, () => throwInvalidIPv4Address(ipv4));
};
const convertIPv6ToBinary = (ipv6) => {
const sections = expandIPv6(ipv6).split(":");
const length = ipv6.length;
const sections = [];
let hasZoneId = false;
let compressAt = -1;
let index = 0;
if (length === 0) {
throwInvalidIPv6Address(ipv6);
}
while (index < length) {
if (sections.length > 8) {
throwInvalidIPv6Address(ipv6);
}
let code = ipv6.charCodeAt(index);
if (code === CHAR_CODE_PERCENT) {
if (index + 1 === length) {
throwInvalidIPv6Address(ipv6);
}
hasZoneId = true;
break;
}
if (code === CHAR_CODE_COLON) {
if (index + 1 < length && ipv6.charCodeAt(index + 1) === CHAR_CODE_COLON) {
if (compressAt !== -1) {
throwInvalidIPv6Address(ipv6);
}
compressAt = sections.length;
index += 2;
continue;
}
throwInvalidIPv6Address(ipv6);
}
let value = 0;
let digits = 0;
const sectionStart = index;
while (index < length) {
code = ipv6.charCodeAt(index);
const hex = parseIPv6HexCode(code);
if (hex === -1) {
break;
}
if (digits === 4) {
throwInvalidIPv6Address(ipv6);
}
value = value << 4 | hex;
digits++;
index++;
}
if (index < length && ipv6.charCodeAt(index) === CHAR_CODE_DOT) {
let ipv4End = length;
for (let i = index; i < length; i++) {
if (ipv6.charCodeAt(i) === CHAR_CODE_PERCENT) {
if (i + 1 === length) {
throwInvalidIPv6Address(ipv6);
}
hasZoneId = true;
ipv4End = i;
break;
}
}
const ipv4 = parseIPv4ToBinary(
ipv6,
sectionStart,
ipv4End,
() => throwInvalidIPv6Address(ipv6)
);
sections.push(Number(ipv4 >> 16n & 0xffffn), Number(ipv4 & 0xffffn));
index = length;
break;
}
if (digits === 0) {
throwInvalidIPv6Address(ipv6);
}
sections.push(value);
if (index === length) {
break;
}
code = ipv6.charCodeAt(index);
if (code === CHAR_CODE_PERCENT) {
if (index + 1 === length) {
throwInvalidIPv6Address(ipv6);
}
hasZoneId = true;
break;
}
if (code !== CHAR_CODE_COLON) {
throwInvalidIPv6Address(ipv6);
}
if (index + 1 < length && ipv6.charCodeAt(index + 1) === CHAR_CODE_COLON) {
if (compressAt !== -1) {
throwInvalidIPv6Address(ipv6);
}
compressAt = sections.length;
index += 2;
continue;
}
index++;
if (index === length) {
throwInvalidIPv6Address(ipv6);
}
}
if (compressAt === -1 ? sections.length !== 8 : sections.length >= 8) {
throwInvalidIPv6Address(ipv6);
}
let result = 0n;
for (let i = 0; i < 8; i++) {
const zeros = compressAt === -1 ? 0 : 8 - sections.length;
const firstSectionEnd = compressAt === -1 ? sections.length : compressAt;
for (let i = 0; i < firstSectionEnd; i++) {
result <<= 16n;
result += BigInt(parseInt(sections[i], 16));
result += BigInt(sections[i]);
}
for (let i = 0; i < zeros; i++) {
result <<= 16n;
}
for (let i = firstSectionEnd; i < sections.length; i++) {
result <<= 16n;
result += BigInt(sections[i]);
}
if (hasZoneId && !isIPv6LinkLocal(result)) {
throwInvalidIPv6Address(ipv6);
}
return result;
};
@@ -82,9 +262,14 @@ const convertIPv4BinaryToString = (ipV4) => {
}
return sections.join(".");
};
const isIPv4MappedIPv6 = (ipv6binary) => ipv6binary >> 32n === 0xffffn;
const convertIPv4MappedIPv6ToIPv4 = (ipv6binary) => ipv6binary & 0xffffffffn;
const convertIPv6BinaryToString = (ipV6) => {
if (ipV6 >> 32n === 0xffffn) {
return `::ffff:${convertIPv4BinaryToString(ipV6 & 0xffffffffn)}`;
if (ipV6 === 0n) {
return "::";
}
if (isIPv4MappedIPv6(ipV6)) {
return `::ffff:${convertIPv4BinaryToString(convertIPv4MappedIPv6ToIPv4(ipV6))}`;
}
const sections = [];
for (let i = 0; i < 8; i++) {
@@ -114,17 +299,20 @@ const convertIPv6BinaryToString = (ipV6) => {
maxZeroEnd = 8;
}
}
if (maxZeroStart !== -1) {
if (maxZeroStart !== -1 && maxZeroEnd - maxZeroStart > 1) {
sections.splice(maxZeroStart, maxZeroEnd - maxZeroStart, ":");
}
return sections.join(":").replace(/:{2,}/g, "::");
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
INVALID_IP_ADDRESS_ERROR_CODE,
convertIPv4BinaryToString,
convertIPv4MappedIPv6ToIPv4,
convertIPv4ToBinary,
convertIPv6BinaryToString,
convertIPv6ToBinary,
distinctRemoteAddr,
expandIPv6
expandIPv6,
isIPv4MappedIPv6
});
-1
View File
@@ -1,4 +1,3 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
-1
View File
@@ -1,4 +1,3 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
+1 -2
View File
@@ -1,4 +1,3 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -37,7 +36,7 @@ async function verifying(publicKey, alg, signature, data) {
return await crypto.subtle.verify(algorithm, cryptoKey, signature, data);
}
function pemToBinary(pem) {
return (0, import_encode.decodeBase64)(pem.replace(/-+(BEGIN|END).*/g, "").replace(/\s/g, ""));
return (0, import_encode.decodeBase64)(pem.replace(/-+(BEGIN|END).*?-+/g, "").replace(/\s/g, ""));
}
async function importPrivateKey(key, alg) {
if (!crypto.subtle || !crypto.subtle.importKey) {
+12 -7
View File
@@ -1,4 +1,3 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -82,14 +81,20 @@ const verify = async (token, publicKey, algOrOptions) => {
throw new import_types.JwtAlgorithmMismatch(alg, header.alg);
}
const now = Math.floor(Date.now() / 1e3);
if (nbf && payload.nbf && payload.nbf > now) {
throw new import_types.JwtTokenNotBefore(token);
if (nbf && payload.nbf !== void 0) {
if (typeof payload.nbf !== "number" || !Number.isFinite(payload.nbf) || payload.nbf > now) {
throw new import_types.JwtTokenNotBefore(token);
}
}
if (exp && payload.exp && payload.exp <= now) {
throw new import_types.JwtTokenExpired(token);
if (exp && payload.exp !== void 0) {
if (typeof payload.exp !== "number" || !Number.isFinite(payload.exp) || payload.exp <= now) {
throw new import_types.JwtTokenExpired(token);
}
}
if (iat && payload.iat && now < payload.iat) {
throw new import_types.JwtTokenIssuedAt(now, payload.iat);
if (iat && payload.iat !== void 0) {
if (typeof payload.iat !== "number" || !Number.isFinite(payload.iat) || now < payload.iat) {
throw new import_types.JwtTokenIssuedAt(now, payload.iat);
}
}
if (iss) {
if (!payload.iss) {
-1
View File
@@ -1,4 +1,3 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
-1
View File
@@ -1,4 +1,3 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
+15 -18
View File
@@ -1,4 +1,3 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -29,15 +28,13 @@ const getMimeType = (filename, mimes = baseMimes) => {
if (!match) {
return;
}
let mimeType = mimes[match[1]];
if (mimeType && mimeType.startsWith("text")) {
mimeType += "; charset=utf-8";
}
return mimeType;
return mimes[match[1].toLowerCase()];
};
const getExtension = (mimeType) => {
const baseType = mimeType.split(";", 1)[0].trim();
for (const ext in baseMimes) {
if (baseMimes[ext] === mimeType) {
const stored = baseMimes[ext];
if (stored === mimeType || stored.split(";", 1)[0].trim() === baseType) {
return ext;
}
}
@@ -49,25 +46,25 @@ const _baseMimes = {
av1: "video/av1",
bin: "application/octet-stream",
bmp: "image/bmp",
css: "text/css",
csv: "text/csv",
css: "text/css; charset=utf-8",
csv: "text/csv; charset=utf-8",
eot: "application/vnd.ms-fontobject",
epub: "application/epub+zip",
gif: "image/gif",
gz: "application/gzip",
htm: "text/html",
html: "text/html",
htm: "text/html; charset=utf-8",
html: "text/html; charset=utf-8",
ico: "image/x-icon",
ics: "text/calendar",
ics: "text/calendar; charset=utf-8",
jpeg: "image/jpeg",
jpg: "image/jpeg",
js: "text/javascript",
js: "text/javascript; charset=utf-8",
json: "application/json",
jsonld: "application/ld+json",
map: "application/json",
mid: "audio/x-midi",
midi: "audio/x-midi",
mjs: "text/javascript",
mjs: "text/javascript; charset=utf-8",
mp3: "audio/mpeg",
mp4: "video/mp4",
mpeg: "video/mpeg",
@@ -79,12 +76,12 @@ const _baseMimes = {
pdf: "application/pdf",
png: "image/png",
rtf: "application/rtf",
svg: "image/svg+xml",
svg: "image/svg+xml; charset=utf-8",
tif: "image/tiff",
tiff: "image/tiff",
ts: "video/mp2t",
ttf: "font/ttf",
txt: "text/plain",
txt: "text/plain; charset=utf-8",
wasm: "application/wasm",
webm: "video/webm",
weba: "audio/webm",
@@ -92,8 +89,8 @@ const _baseMimes = {
webp: "image/webp",
woff: "font/woff",
woff2: "font/woff2",
xhtml: "application/xhtml+xml",
xml: "application/xml",
xhtml: "application/xhtml+xml; charset=utf-8",
xml: "application/xml; charset=utf-8",
zip: "application/zip",
"3gp": "video/3gpp",
"3g2": "video/3gpp2",
+4 -3
View File
@@ -1,4 +1,3 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -49,7 +48,9 @@ class StreamingApi {
done ? controller.close() : controller.enqueue(value);
},
cancel: () => {
this.abort();
if (!this.closed) {
this.abort();
}
}
});
}
@@ -71,11 +72,11 @@ class StreamingApi {
return new Promise((res) => setTimeout(res, ms));
}
async close() {
this.closed = true;
try {
await this.writer.close();
} catch {
}
this.closed = true;
}
async pipe(body) {
this.writer.releaseLock();
-1
View File
@@ -1,4 +1,3 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
-1
View File
@@ -1,4 +1,3 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;