h3-nightly 2.0.1-20251021-150751-3e92a35 → 3.0.0-20251021-151501-4247682
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/h3.mjs +174 -215
- package/package.json +1 -1
package/dist/h3.mjs
CHANGED
|
@@ -1481,219 +1481,6 @@ function onError(hook) {
|
|
|
1481
1481
|
};
|
|
1482
1482
|
}
|
|
1483
1483
|
|
|
1484
|
-
//#endregion
|
|
1485
|
-
//#region node_modules/.pnpm/cookie-es@2.0.0/node_modules/cookie-es/dist/index.mjs
|
|
1486
|
-
function parse(str, options) {
|
|
1487
|
-
if (typeof str !== "string") throw new TypeError("argument str must be a string");
|
|
1488
|
-
const obj = {};
|
|
1489
|
-
const opt = options || {};
|
|
1490
|
-
const dec = opt.decode || decode;
|
|
1491
|
-
let index = 0;
|
|
1492
|
-
while (index < str.length) {
|
|
1493
|
-
const eqIdx = str.indexOf("=", index);
|
|
1494
|
-
if (eqIdx === -1) break;
|
|
1495
|
-
let endIdx = str.indexOf(";", index);
|
|
1496
|
-
if (endIdx === -1) endIdx = str.length;
|
|
1497
|
-
else if (endIdx < eqIdx) {
|
|
1498
|
-
index = str.lastIndexOf(";", eqIdx - 1) + 1;
|
|
1499
|
-
continue;
|
|
1500
|
-
}
|
|
1501
|
-
const key = str.slice(index, eqIdx).trim();
|
|
1502
|
-
if (opt?.filter && !opt?.filter(key)) {
|
|
1503
|
-
index = endIdx + 1;
|
|
1504
|
-
continue;
|
|
1505
|
-
}
|
|
1506
|
-
if (void 0 === obj[key]) {
|
|
1507
|
-
let val = str.slice(eqIdx + 1, endIdx).trim();
|
|
1508
|
-
if (val.codePointAt(0) === 34) val = val.slice(1, -1);
|
|
1509
|
-
obj[key] = tryDecode(val, dec);
|
|
1510
|
-
}
|
|
1511
|
-
index = endIdx + 1;
|
|
1512
|
-
}
|
|
1513
|
-
return obj;
|
|
1514
|
-
}
|
|
1515
|
-
function decode(str) {
|
|
1516
|
-
return str.includes("%") ? decodeURIComponent(str) : str;
|
|
1517
|
-
}
|
|
1518
|
-
function tryDecode(str, decode2) {
|
|
1519
|
-
try {
|
|
1520
|
-
return decode2(str);
|
|
1521
|
-
} catch {
|
|
1522
|
-
return str;
|
|
1523
|
-
}
|
|
1524
|
-
}
|
|
1525
|
-
const fieldContentRegExp = /^[\u0009\u0020-\u007E\u0080-\u00FF]+$/;
|
|
1526
|
-
function serialize(name, value, options) {
|
|
1527
|
-
const opt = options || {};
|
|
1528
|
-
const enc = opt.encode || encodeURIComponent;
|
|
1529
|
-
if (typeof enc !== "function") throw new TypeError("option encode is invalid");
|
|
1530
|
-
if (!fieldContentRegExp.test(name)) throw new TypeError("argument name is invalid");
|
|
1531
|
-
const encodedValue = enc(value);
|
|
1532
|
-
if (encodedValue && !fieldContentRegExp.test(encodedValue)) throw new TypeError("argument val is invalid");
|
|
1533
|
-
let str = name + "=" + encodedValue;
|
|
1534
|
-
if (void 0 !== opt.maxAge && opt.maxAge !== null) {
|
|
1535
|
-
const maxAge = opt.maxAge - 0;
|
|
1536
|
-
if (Number.isNaN(maxAge) || !Number.isFinite(maxAge)) throw new TypeError("option maxAge is invalid");
|
|
1537
|
-
str += "; Max-Age=" + Math.floor(maxAge);
|
|
1538
|
-
}
|
|
1539
|
-
if (opt.domain) {
|
|
1540
|
-
if (!fieldContentRegExp.test(opt.domain)) throw new TypeError("option domain is invalid");
|
|
1541
|
-
str += "; Domain=" + opt.domain;
|
|
1542
|
-
}
|
|
1543
|
-
if (opt.path) {
|
|
1544
|
-
if (!fieldContentRegExp.test(opt.path)) throw new TypeError("option path is invalid");
|
|
1545
|
-
str += "; Path=" + opt.path;
|
|
1546
|
-
}
|
|
1547
|
-
if (opt.expires) {
|
|
1548
|
-
if (!isDate(opt.expires) || Number.isNaN(opt.expires.valueOf())) throw new TypeError("option expires is invalid");
|
|
1549
|
-
str += "; Expires=" + opt.expires.toUTCString();
|
|
1550
|
-
}
|
|
1551
|
-
if (opt.httpOnly) str += "; HttpOnly";
|
|
1552
|
-
if (opt.secure) str += "; Secure";
|
|
1553
|
-
if (opt.priority) {
|
|
1554
|
-
const priority = typeof opt.priority === "string" ? opt.priority.toLowerCase() : opt.priority;
|
|
1555
|
-
switch (priority) {
|
|
1556
|
-
case "low": {
|
|
1557
|
-
str += "; Priority=Low";
|
|
1558
|
-
break;
|
|
1559
|
-
}
|
|
1560
|
-
case "medium": {
|
|
1561
|
-
str += "; Priority=Medium";
|
|
1562
|
-
break;
|
|
1563
|
-
}
|
|
1564
|
-
case "high": {
|
|
1565
|
-
str += "; Priority=High";
|
|
1566
|
-
break;
|
|
1567
|
-
}
|
|
1568
|
-
default: throw new TypeError("option priority is invalid");
|
|
1569
|
-
}
|
|
1570
|
-
}
|
|
1571
|
-
if (opt.sameSite) {
|
|
1572
|
-
const sameSite = typeof opt.sameSite === "string" ? opt.sameSite.toLowerCase() : opt.sameSite;
|
|
1573
|
-
switch (sameSite) {
|
|
1574
|
-
case true: {
|
|
1575
|
-
str += "; SameSite=Strict";
|
|
1576
|
-
break;
|
|
1577
|
-
}
|
|
1578
|
-
case "lax": {
|
|
1579
|
-
str += "; SameSite=Lax";
|
|
1580
|
-
break;
|
|
1581
|
-
}
|
|
1582
|
-
case "strict": {
|
|
1583
|
-
str += "; SameSite=Strict";
|
|
1584
|
-
break;
|
|
1585
|
-
}
|
|
1586
|
-
case "none": {
|
|
1587
|
-
str += "; SameSite=None";
|
|
1588
|
-
break;
|
|
1589
|
-
}
|
|
1590
|
-
default: throw new TypeError("option sameSite is invalid");
|
|
1591
|
-
}
|
|
1592
|
-
}
|
|
1593
|
-
if (opt.partitioned) str += "; Partitioned";
|
|
1594
|
-
return str;
|
|
1595
|
-
}
|
|
1596
|
-
function isDate(val) {
|
|
1597
|
-
return Object.prototype.toString.call(val) === "[object Date]" || val instanceof Date;
|
|
1598
|
-
}
|
|
1599
|
-
function parseSetCookie(setCookieValue, options) {
|
|
1600
|
-
const parts = (setCookieValue || "").split(";").filter((str) => typeof str === "string" && !!str.trim());
|
|
1601
|
-
const nameValuePairStr = parts.shift() || "";
|
|
1602
|
-
const parsed = _parseNameValuePair(nameValuePairStr);
|
|
1603
|
-
const name = parsed.name;
|
|
1604
|
-
let value = parsed.value;
|
|
1605
|
-
try {
|
|
1606
|
-
value = options?.decode === false ? value : (options?.decode || decodeURIComponent)(value);
|
|
1607
|
-
} catch {}
|
|
1608
|
-
const cookie = {
|
|
1609
|
-
name,
|
|
1610
|
-
value
|
|
1611
|
-
};
|
|
1612
|
-
for (const part of parts) {
|
|
1613
|
-
const sides = part.split("=");
|
|
1614
|
-
const partKey = (sides.shift() || "").trimStart().toLowerCase();
|
|
1615
|
-
const partValue = sides.join("=");
|
|
1616
|
-
switch (partKey) {
|
|
1617
|
-
case "expires": {
|
|
1618
|
-
cookie.expires = new Date(partValue);
|
|
1619
|
-
break;
|
|
1620
|
-
}
|
|
1621
|
-
case "max-age": {
|
|
1622
|
-
cookie.maxAge = Number.parseInt(partValue, 10);
|
|
1623
|
-
break;
|
|
1624
|
-
}
|
|
1625
|
-
case "secure": {
|
|
1626
|
-
cookie.secure = true;
|
|
1627
|
-
break;
|
|
1628
|
-
}
|
|
1629
|
-
case "httponly": {
|
|
1630
|
-
cookie.httpOnly = true;
|
|
1631
|
-
break;
|
|
1632
|
-
}
|
|
1633
|
-
case "samesite": {
|
|
1634
|
-
cookie.sameSite = partValue;
|
|
1635
|
-
break;
|
|
1636
|
-
}
|
|
1637
|
-
default: cookie[partKey] = partValue;
|
|
1638
|
-
}
|
|
1639
|
-
}
|
|
1640
|
-
return cookie;
|
|
1641
|
-
}
|
|
1642
|
-
function _parseNameValuePair(nameValuePairStr) {
|
|
1643
|
-
let name = "";
|
|
1644
|
-
let value = "";
|
|
1645
|
-
const nameValueArr = nameValuePairStr.split("=");
|
|
1646
|
-
if (nameValueArr.length > 1) {
|
|
1647
|
-
name = nameValueArr.shift();
|
|
1648
|
-
value = nameValueArr.join("=");
|
|
1649
|
-
} else value = nameValuePairStr;
|
|
1650
|
-
return {
|
|
1651
|
-
name,
|
|
1652
|
-
value
|
|
1653
|
-
};
|
|
1654
|
-
}
|
|
1655
|
-
function splitSetCookieString(cookiesString) {
|
|
1656
|
-
if (Array.isArray(cookiesString)) return cookiesString.flatMap((c) => splitSetCookieString(c));
|
|
1657
|
-
if (typeof cookiesString !== "string") return [];
|
|
1658
|
-
const cookiesStrings = [];
|
|
1659
|
-
let pos = 0;
|
|
1660
|
-
let start;
|
|
1661
|
-
let ch;
|
|
1662
|
-
let lastComma;
|
|
1663
|
-
let nextStart;
|
|
1664
|
-
let cookiesSeparatorFound;
|
|
1665
|
-
const skipWhitespace = () => {
|
|
1666
|
-
while (pos < cookiesString.length && /\s/.test(cookiesString.charAt(pos))) pos += 1;
|
|
1667
|
-
return pos < cookiesString.length;
|
|
1668
|
-
};
|
|
1669
|
-
const notSpecialChar = () => {
|
|
1670
|
-
ch = cookiesString.charAt(pos);
|
|
1671
|
-
return ch !== "=" && ch !== ";" && ch !== ",";
|
|
1672
|
-
};
|
|
1673
|
-
while (pos < cookiesString.length) {
|
|
1674
|
-
start = pos;
|
|
1675
|
-
cookiesSeparatorFound = false;
|
|
1676
|
-
while (skipWhitespace()) {
|
|
1677
|
-
ch = cookiesString.charAt(pos);
|
|
1678
|
-
if (ch === ",") {
|
|
1679
|
-
lastComma = pos;
|
|
1680
|
-
pos += 1;
|
|
1681
|
-
skipWhitespace();
|
|
1682
|
-
nextStart = pos;
|
|
1683
|
-
while (pos < cookiesString.length && notSpecialChar()) pos += 1;
|
|
1684
|
-
if (pos < cookiesString.length && cookiesString.charAt(pos) === "=") {
|
|
1685
|
-
cookiesSeparatorFound = true;
|
|
1686
|
-
pos = nextStart;
|
|
1687
|
-
cookiesStrings.push(cookiesString.slice(start, lastComma));
|
|
1688
|
-
start = pos;
|
|
1689
|
-
} else pos = lastComma + 1;
|
|
1690
|
-
} else pos += 1;
|
|
1691
|
-
}
|
|
1692
|
-
if (!cookiesSeparatorFound || pos >= cookiesString.length) cookiesStrings.push(cookiesString.slice(start));
|
|
1693
|
-
}
|
|
1694
|
-
return cookiesStrings;
|
|
1695
|
-
}
|
|
1696
|
-
|
|
1697
1484
|
//#endregion
|
|
1698
1485
|
//#region src/utils/internal/proxy.ts
|
|
1699
1486
|
const PayloadMethods = new Set([
|
|
@@ -1779,10 +1566,10 @@ async function proxy(event, target, opts = {}) {
|
|
|
1779
1566
|
if (key === "content-encoding") continue;
|
|
1780
1567
|
if (key === "content-length") continue;
|
|
1781
1568
|
if (key === "set-cookie") {
|
|
1782
|
-
cookies.push(
|
|
1569
|
+
cookies.push(value);
|
|
1783
1570
|
continue;
|
|
1784
1571
|
}
|
|
1785
|
-
headers.
|
|
1572
|
+
headers.append(key, value);
|
|
1786
1573
|
}
|
|
1787
1574
|
if (cookies.length > 0) {
|
|
1788
1575
|
const _cookies = cookies.map((cookie) => {
|
|
@@ -1911,6 +1698,178 @@ async function readValidatedBody(event, validate) {
|
|
|
1911
1698
|
return validateData(_body, validate);
|
|
1912
1699
|
}
|
|
1913
1700
|
|
|
1701
|
+
//#endregion
|
|
1702
|
+
//#region node_modules/.pnpm/cookie-es@2.0.0/node_modules/cookie-es/dist/index.mjs
|
|
1703
|
+
function parse(str, options) {
|
|
1704
|
+
if (typeof str !== "string") throw new TypeError("argument str must be a string");
|
|
1705
|
+
const obj = {};
|
|
1706
|
+
const opt = options || {};
|
|
1707
|
+
const dec = opt.decode || decode;
|
|
1708
|
+
let index = 0;
|
|
1709
|
+
while (index < str.length) {
|
|
1710
|
+
const eqIdx = str.indexOf("=", index);
|
|
1711
|
+
if (eqIdx === -1) break;
|
|
1712
|
+
let endIdx = str.indexOf(";", index);
|
|
1713
|
+
if (endIdx === -1) endIdx = str.length;
|
|
1714
|
+
else if (endIdx < eqIdx) {
|
|
1715
|
+
index = str.lastIndexOf(";", eqIdx - 1) + 1;
|
|
1716
|
+
continue;
|
|
1717
|
+
}
|
|
1718
|
+
const key = str.slice(index, eqIdx).trim();
|
|
1719
|
+
if (opt?.filter && !opt?.filter(key)) {
|
|
1720
|
+
index = endIdx + 1;
|
|
1721
|
+
continue;
|
|
1722
|
+
}
|
|
1723
|
+
if (void 0 === obj[key]) {
|
|
1724
|
+
let val = str.slice(eqIdx + 1, endIdx).trim();
|
|
1725
|
+
if (val.codePointAt(0) === 34) val = val.slice(1, -1);
|
|
1726
|
+
obj[key] = tryDecode(val, dec);
|
|
1727
|
+
}
|
|
1728
|
+
index = endIdx + 1;
|
|
1729
|
+
}
|
|
1730
|
+
return obj;
|
|
1731
|
+
}
|
|
1732
|
+
function decode(str) {
|
|
1733
|
+
return str.includes("%") ? decodeURIComponent(str) : str;
|
|
1734
|
+
}
|
|
1735
|
+
function tryDecode(str, decode2) {
|
|
1736
|
+
try {
|
|
1737
|
+
return decode2(str);
|
|
1738
|
+
} catch {
|
|
1739
|
+
return str;
|
|
1740
|
+
}
|
|
1741
|
+
}
|
|
1742
|
+
const fieldContentRegExp = /^[\u0009\u0020-\u007E\u0080-\u00FF]+$/;
|
|
1743
|
+
function serialize(name, value, options) {
|
|
1744
|
+
const opt = options || {};
|
|
1745
|
+
const enc = opt.encode || encodeURIComponent;
|
|
1746
|
+
if (typeof enc !== "function") throw new TypeError("option encode is invalid");
|
|
1747
|
+
if (!fieldContentRegExp.test(name)) throw new TypeError("argument name is invalid");
|
|
1748
|
+
const encodedValue = enc(value);
|
|
1749
|
+
if (encodedValue && !fieldContentRegExp.test(encodedValue)) throw new TypeError("argument val is invalid");
|
|
1750
|
+
let str = name + "=" + encodedValue;
|
|
1751
|
+
if (void 0 !== opt.maxAge && opt.maxAge !== null) {
|
|
1752
|
+
const maxAge = opt.maxAge - 0;
|
|
1753
|
+
if (Number.isNaN(maxAge) || !Number.isFinite(maxAge)) throw new TypeError("option maxAge is invalid");
|
|
1754
|
+
str += "; Max-Age=" + Math.floor(maxAge);
|
|
1755
|
+
}
|
|
1756
|
+
if (opt.domain) {
|
|
1757
|
+
if (!fieldContentRegExp.test(opt.domain)) throw new TypeError("option domain is invalid");
|
|
1758
|
+
str += "; Domain=" + opt.domain;
|
|
1759
|
+
}
|
|
1760
|
+
if (opt.path) {
|
|
1761
|
+
if (!fieldContentRegExp.test(opt.path)) throw new TypeError("option path is invalid");
|
|
1762
|
+
str += "; Path=" + opt.path;
|
|
1763
|
+
}
|
|
1764
|
+
if (opt.expires) {
|
|
1765
|
+
if (!isDate(opt.expires) || Number.isNaN(opt.expires.valueOf())) throw new TypeError("option expires is invalid");
|
|
1766
|
+
str += "; Expires=" + opt.expires.toUTCString();
|
|
1767
|
+
}
|
|
1768
|
+
if (opt.httpOnly) str += "; HttpOnly";
|
|
1769
|
+
if (opt.secure) str += "; Secure";
|
|
1770
|
+
if (opt.priority) {
|
|
1771
|
+
const priority = typeof opt.priority === "string" ? opt.priority.toLowerCase() : opt.priority;
|
|
1772
|
+
switch (priority) {
|
|
1773
|
+
case "low": {
|
|
1774
|
+
str += "; Priority=Low";
|
|
1775
|
+
break;
|
|
1776
|
+
}
|
|
1777
|
+
case "medium": {
|
|
1778
|
+
str += "; Priority=Medium";
|
|
1779
|
+
break;
|
|
1780
|
+
}
|
|
1781
|
+
case "high": {
|
|
1782
|
+
str += "; Priority=High";
|
|
1783
|
+
break;
|
|
1784
|
+
}
|
|
1785
|
+
default: throw new TypeError("option priority is invalid");
|
|
1786
|
+
}
|
|
1787
|
+
}
|
|
1788
|
+
if (opt.sameSite) {
|
|
1789
|
+
const sameSite = typeof opt.sameSite === "string" ? opt.sameSite.toLowerCase() : opt.sameSite;
|
|
1790
|
+
switch (sameSite) {
|
|
1791
|
+
case true: {
|
|
1792
|
+
str += "; SameSite=Strict";
|
|
1793
|
+
break;
|
|
1794
|
+
}
|
|
1795
|
+
case "lax": {
|
|
1796
|
+
str += "; SameSite=Lax";
|
|
1797
|
+
break;
|
|
1798
|
+
}
|
|
1799
|
+
case "strict": {
|
|
1800
|
+
str += "; SameSite=Strict";
|
|
1801
|
+
break;
|
|
1802
|
+
}
|
|
1803
|
+
case "none": {
|
|
1804
|
+
str += "; SameSite=None";
|
|
1805
|
+
break;
|
|
1806
|
+
}
|
|
1807
|
+
default: throw new TypeError("option sameSite is invalid");
|
|
1808
|
+
}
|
|
1809
|
+
}
|
|
1810
|
+
if (opt.partitioned) str += "; Partitioned";
|
|
1811
|
+
return str;
|
|
1812
|
+
}
|
|
1813
|
+
function isDate(val) {
|
|
1814
|
+
return Object.prototype.toString.call(val) === "[object Date]" || val instanceof Date;
|
|
1815
|
+
}
|
|
1816
|
+
function parseSetCookie(setCookieValue, options) {
|
|
1817
|
+
const parts = (setCookieValue || "").split(";").filter((str) => typeof str === "string" && !!str.trim());
|
|
1818
|
+
const nameValuePairStr = parts.shift() || "";
|
|
1819
|
+
const parsed = _parseNameValuePair(nameValuePairStr);
|
|
1820
|
+
const name = parsed.name;
|
|
1821
|
+
let value = parsed.value;
|
|
1822
|
+
try {
|
|
1823
|
+
value = options?.decode === false ? value : (options?.decode || decodeURIComponent)(value);
|
|
1824
|
+
} catch {}
|
|
1825
|
+
const cookie = {
|
|
1826
|
+
name,
|
|
1827
|
+
value
|
|
1828
|
+
};
|
|
1829
|
+
for (const part of parts) {
|
|
1830
|
+
const sides = part.split("=");
|
|
1831
|
+
const partKey = (sides.shift() || "").trimStart().toLowerCase();
|
|
1832
|
+
const partValue = sides.join("=");
|
|
1833
|
+
switch (partKey) {
|
|
1834
|
+
case "expires": {
|
|
1835
|
+
cookie.expires = new Date(partValue);
|
|
1836
|
+
break;
|
|
1837
|
+
}
|
|
1838
|
+
case "max-age": {
|
|
1839
|
+
cookie.maxAge = Number.parseInt(partValue, 10);
|
|
1840
|
+
break;
|
|
1841
|
+
}
|
|
1842
|
+
case "secure": {
|
|
1843
|
+
cookie.secure = true;
|
|
1844
|
+
break;
|
|
1845
|
+
}
|
|
1846
|
+
case "httponly": {
|
|
1847
|
+
cookie.httpOnly = true;
|
|
1848
|
+
break;
|
|
1849
|
+
}
|
|
1850
|
+
case "samesite": {
|
|
1851
|
+
cookie.sameSite = partValue;
|
|
1852
|
+
break;
|
|
1853
|
+
}
|
|
1854
|
+
default: cookie[partKey] = partValue;
|
|
1855
|
+
}
|
|
1856
|
+
}
|
|
1857
|
+
return cookie;
|
|
1858
|
+
}
|
|
1859
|
+
function _parseNameValuePair(nameValuePairStr) {
|
|
1860
|
+
let name = "";
|
|
1861
|
+
let value = "";
|
|
1862
|
+
const nameValueArr = nameValuePairStr.split("=");
|
|
1863
|
+
if (nameValueArr.length > 1) {
|
|
1864
|
+
name = nameValueArr.shift();
|
|
1865
|
+
value = nameValueArr.join("=");
|
|
1866
|
+
} else value = nameValuePairStr;
|
|
1867
|
+
return {
|
|
1868
|
+
name,
|
|
1869
|
+
value
|
|
1870
|
+
};
|
|
1871
|
+
}
|
|
1872
|
+
|
|
1914
1873
|
//#endregion
|
|
1915
1874
|
//#region src/utils/cookie.ts
|
|
1916
1875
|
const CHUNKED_COOKIE = "__chunked__";
|
package/package.json
CHANGED