formacao
This commit is contained in:
+188
-28
@@ -1,30 +1,197 @@
|
||||
// src/utils/accept.ts
|
||||
var isWhitespace = (char) => char === 32 || char === 9 || char === 10 || char === 13;
|
||||
var consumeWhitespace = (acceptHeader, startIndex) => {
|
||||
while (startIndex < acceptHeader.length) {
|
||||
if (!isWhitespace(acceptHeader.charCodeAt(startIndex))) {
|
||||
break;
|
||||
}
|
||||
startIndex++;
|
||||
}
|
||||
return startIndex;
|
||||
};
|
||||
var ignoreTrailingWhitespace = (acceptHeader, startIndex) => {
|
||||
while (startIndex > 0) {
|
||||
if (!isWhitespace(acceptHeader.charCodeAt(startIndex - 1))) {
|
||||
break;
|
||||
}
|
||||
startIndex--;
|
||||
}
|
||||
return startIndex;
|
||||
};
|
||||
var 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];
|
||||
};
|
||||
var 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;
|
||||
};
|
||||
var 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
|
||||
];
|
||||
};
|
||||
var 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];
|
||||
};
|
||||
var 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 }));
|
||||
};
|
||||
var parseAcceptValueRegex = /;(?=(?:(?:[^"]*"){2})*[^"]*$)/;
|
||||
var 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 };
|
||||
};
|
||||
var 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;
|
||||
};
|
||||
var parseQuality = (qVal) => {
|
||||
if (qVal === void 0) {
|
||||
@@ -51,13 +218,6 @@ var parseQuality = (qVal) => {
|
||||
}
|
||||
return num;
|
||||
};
|
||||
var sortByQualityAndIndex = (a, b) => {
|
||||
const qDiff = b.q - a.q;
|
||||
if (qDiff !== 0) {
|
||||
return qDiff;
|
||||
}
|
||||
return a.index - b.index;
|
||||
};
|
||||
export {
|
||||
parseAccept
|
||||
};
|
||||
|
||||
+3
@@ -54,6 +54,9 @@ var handleParsingAllValues = (form, key, value) => {
|
||||
}
|
||||
};
|
||||
var handleParsingNestedValues = (form, key, value) => {
|
||||
if (/(?:^|\.)__proto__\./.test(key)) {
|
||||
return;
|
||||
}
|
||||
let nestedForm = form;
|
||||
const keys = key.split(".");
|
||||
keys.forEach((key2, index) => {
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
// src/utils/compress.ts
|
||||
var 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;
|
||||
var 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;
|
||||
export {
|
||||
COMPRESSIBLE_CONTENT_TYPE_REGEX
|
||||
};
|
||||
|
||||
+30
-9
@@ -24,23 +24,41 @@ var verifySignature = async (base64Signature, value, secret) => {
|
||||
};
|
||||
var validCookieNameRegEx = /^[\w!#$%&'*.^`|~+-]+$/;
|
||||
var validCookieValueRegEx = /^[ !#-:<-[\]-~]*$/;
|
||||
var 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);
|
||||
};
|
||||
var 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);
|
||||
}
|
||||
@@ -54,7 +72,7 @@ var parse = (cookie, name) => {
|
||||
return parsedCookie;
|
||||
};
|
||||
var 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(".");
|
||||
@@ -72,6 +90,9 @@ var parseSigned = async (cookie, secret, name) => {
|
||||
return parsedCookie;
|
||||
};
|
||||
var _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");
|
||||
@@ -87,7 +108,7 @@ var _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
-1
@@ -20,7 +20,7 @@ var 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(/^\.?\//, "");
|
||||
|
||||
+199
-13
@@ -14,7 +14,9 @@ var 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(":");
|
||||
}
|
||||
}
|
||||
@@ -22,6 +24,16 @@ var expandIPv6 = (ipV6) => {
|
||||
};
|
||||
var IPV4_OCTET_PART = "(?:25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])";
|
||||
var IPV4_REGEX = new RegExp(`^(?:${IPV4_OCTET_PART}\\.){3}${IPV4_OCTET_PART}$`);
|
||||
var INVALID_IP_ADDRESS_ERROR_CODE = "ERR_INVALID_IP_ADDRESS";
|
||||
var CHAR_CODE_0 = 48;
|
||||
var CHAR_CODE_9 = 57;
|
||||
var CHAR_CODE_A = 65;
|
||||
var CHAR_CODE_F = 70;
|
||||
var CHAR_CODE_a = 97;
|
||||
var CHAR_CODE_f = 102;
|
||||
var CHAR_CODE_DOT = 46;
|
||||
var CHAR_CODE_COLON = 58;
|
||||
var CHAR_CODE_PERCENT = 37;
|
||||
var distinctRemoteAddr = (remoteAddr) => {
|
||||
if (IPV4_REGEX.test(remoteAddr)) {
|
||||
return "IPv4";
|
||||
@@ -30,21 +42,187 @@ var distinctRemoteAddr = (remoteAddr) => {
|
||||
return "IPv6";
|
||||
}
|
||||
};
|
||||
var convertIPv4ToBinary = (ipv4) => {
|
||||
const parts = ipv4.split(".");
|
||||
var createInvalidIPAddressError = (message) => {
|
||||
const error = new TypeError(message);
|
||||
error.code = INVALID_IP_ADDRESS_ERROR_CODE;
|
||||
return error;
|
||||
};
|
||||
var throwInvalidIPv4Address = (ipv4) => {
|
||||
throw createInvalidIPAddressError(`Invalid IPv4 address: ${ipv4}`);
|
||||
};
|
||||
var throwInvalidIPv6Address = (ipv6) => {
|
||||
throw createInvalidIPAddressError(`Invalid IPv6 address: ${ipv6}`);
|
||||
};
|
||||
var 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;
|
||||
};
|
||||
var 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;
|
||||
};
|
||||
var isIPv6LinkLocal = (ipv6binary) => ipv6binary >> 118n === 0x3fan;
|
||||
var convertIPv4ToBinary = (ipv4) => {
|
||||
return parseIPv4ToBinary(ipv4, 0, ipv4.length, () => throwInvalidIPv4Address(ipv4));
|
||||
};
|
||||
var 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;
|
||||
};
|
||||
@@ -55,9 +233,14 @@ var convertIPv4BinaryToString = (ipV4) => {
|
||||
}
|
||||
return sections.join(".");
|
||||
};
|
||||
var isIPv4MappedIPv6 = (ipv6binary) => ipv6binary >> 32n === 0xffffn;
|
||||
var convertIPv4MappedIPv6ToIPv4 = (ipv6binary) => ipv6binary & 0xffffffffn;
|
||||
var 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++) {
|
||||
@@ -87,16 +270,19 @@ var convertIPv6BinaryToString = (ipV6) => {
|
||||
maxZeroEnd = 8;
|
||||
}
|
||||
}
|
||||
if (maxZeroStart !== -1) {
|
||||
if (maxZeroStart !== -1 && maxZeroEnd - maxZeroStart > 1) {
|
||||
sections.splice(maxZeroStart, maxZeroEnd - maxZeroStart, ":");
|
||||
}
|
||||
return sections.join(":").replace(/:{2,}/g, "::");
|
||||
};
|
||||
export {
|
||||
INVALID_IP_ADDRESS_ERROR_CODE,
|
||||
convertIPv4BinaryToString,
|
||||
convertIPv4MappedIPv6ToIPv4,
|
||||
convertIPv4ToBinary,
|
||||
convertIPv6BinaryToString,
|
||||
convertIPv6ToBinary,
|
||||
distinctRemoteAddr,
|
||||
expandIPv6
|
||||
expandIPv6,
|
||||
isIPv4MappedIPv6
|
||||
};
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@ async function verifying(publicKey, alg, signature, data) {
|
||||
return await crypto.subtle.verify(algorithm, cryptoKey, signature, data);
|
||||
}
|
||||
function pemToBinary(pem) {
|
||||
return decodeBase64(pem.replace(/-+(BEGIN|END).*/g, "").replace(/\s/g, ""));
|
||||
return decodeBase64(pem.replace(/-+(BEGIN|END).*?-+/g, "").replace(/\s/g, ""));
|
||||
}
|
||||
async function importPrivateKey(key, alg) {
|
||||
if (!crypto.subtle || !crypto.subtle.importKey) {
|
||||
|
||||
+12
-6
@@ -70,14 +70,20 @@ var verify = async (token, publicKey, algOrOptions) => {
|
||||
throw new JwtAlgorithmMismatch(alg, header.alg);
|
||||
}
|
||||
const now = Math.floor(Date.now() / 1e3);
|
||||
if (nbf && payload.nbf && payload.nbf > now) {
|
||||
throw new JwtTokenNotBefore(token);
|
||||
if (nbf && payload.nbf !== void 0) {
|
||||
if (typeof payload.nbf !== "number" || !Number.isFinite(payload.nbf) || payload.nbf > now) {
|
||||
throw new JwtTokenNotBefore(token);
|
||||
}
|
||||
}
|
||||
if (exp && payload.exp && payload.exp <= now) {
|
||||
throw new JwtTokenExpired(token);
|
||||
if (exp && payload.exp !== void 0) {
|
||||
if (typeof payload.exp !== "number" || !Number.isFinite(payload.exp) || payload.exp <= now) {
|
||||
throw new JwtTokenExpired(token);
|
||||
}
|
||||
}
|
||||
if (iat && payload.iat && now < payload.iat) {
|
||||
throw new JwtTokenIssuedAt(now, payload.iat);
|
||||
if (iat && payload.iat !== void 0) {
|
||||
if (typeof payload.iat !== "number" || !Number.isFinite(payload.iat) || now < payload.iat) {
|
||||
throw new JwtTokenIssuedAt(now, payload.iat);
|
||||
}
|
||||
}
|
||||
if (iss) {
|
||||
if (!payload.iss) {
|
||||
|
||||
+15
-17
@@ -5,15 +5,13 @@ var 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()];
|
||||
};
|
||||
var 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;
|
||||
}
|
||||
}
|
||||
@@ -25,25 +23,25 @@ var _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",
|
||||
@@ -55,12 +53,12 @@ var _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",
|
||||
@@ -68,8 +66,8 @@ var _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
-2
@@ -27,7 +27,9 @@ var StreamingApi = class {
|
||||
done ? controller.close() : controller.enqueue(value);
|
||||
},
|
||||
cancel: () => {
|
||||
this.abort();
|
||||
if (!this.closed) {
|
||||
this.abort();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -49,11 +51,11 @@ var StreamingApi = class {
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user