h3 1.15.0 → 1.15.1
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/index.cjs +33 -12
- package/dist/index.mjs +34 -13
- package/package.json +1 -2
package/dist/index.cjs
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
const ufo = require('ufo');
|
|
4
4
|
const cookieEs = require('cookie-es');
|
|
5
|
-
const ohash = require('ohash');
|
|
6
5
|
const radix3 = require('radix3');
|
|
7
6
|
const destr = require('destr');
|
|
8
7
|
const defu = require('defu');
|
|
@@ -593,24 +592,46 @@ function sanitizeStatusCode(statusCode, defaultStatusCode = 200) {
|
|
|
593
592
|
return statusCode;
|
|
594
593
|
}
|
|
595
594
|
|
|
595
|
+
function getDistinctCookieKey(name, opts) {
|
|
596
|
+
return [
|
|
597
|
+
name,
|
|
598
|
+
opts.domain || "",
|
|
599
|
+
opts.path || "/",
|
|
600
|
+
Boolean(opts.secure),
|
|
601
|
+
Boolean(opts.httpOnly),
|
|
602
|
+
Boolean(opts.sameSite)
|
|
603
|
+
].join(";");
|
|
604
|
+
}
|
|
605
|
+
|
|
596
606
|
function parseCookies(event) {
|
|
597
607
|
return cookieEs.parse(event.node.req.headers.cookie || "");
|
|
598
608
|
}
|
|
599
609
|
function getCookie(event, name) {
|
|
600
610
|
return parseCookies(event)[name];
|
|
601
611
|
}
|
|
602
|
-
function setCookie(event, name, value, serializeOptions) {
|
|
603
|
-
serializeOptions
|
|
604
|
-
|
|
605
|
-
let setCookies = event.node.res.getHeader("set-cookie");
|
|
606
|
-
if (!Array.isArray(setCookies)) {
|
|
607
|
-
setCookies = [setCookies];
|
|
612
|
+
function setCookie(event, name, value, serializeOptions = {}) {
|
|
613
|
+
if (!serializeOptions.path) {
|
|
614
|
+
serializeOptions = { path: "/", ...serializeOptions };
|
|
608
615
|
}
|
|
609
|
-
const
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
616
|
+
const newCookie = cookieEs.serialize(name, value, serializeOptions);
|
|
617
|
+
const currentCookies = splitCookiesString(
|
|
618
|
+
event.node.res.getHeader("set-cookie")
|
|
619
|
+
);
|
|
620
|
+
if (currentCookies.length === 0) {
|
|
621
|
+
event.node.res.setHeader("set-cookie", newCookie);
|
|
622
|
+
return;
|
|
623
|
+
}
|
|
624
|
+
const newCookieKey = getDistinctCookieKey(name, serializeOptions);
|
|
625
|
+
event.node.res.removeHeader("set-cookie");
|
|
626
|
+
for (const cookie of currentCookies) {
|
|
627
|
+
const parsed = cookieEs.parseSetCookie(cookie);
|
|
628
|
+
const key = getDistinctCookieKey(parsed.name, parsed);
|
|
629
|
+
if (key === newCookieKey) {
|
|
630
|
+
continue;
|
|
631
|
+
}
|
|
632
|
+
event.node.res.appendHeader("set-cookie", cookie);
|
|
633
|
+
}
|
|
634
|
+
event.node.res.appendHeader("set-cookie", newCookie);
|
|
614
635
|
}
|
|
615
636
|
function deleteCookie(event, name, serializeOptions) {
|
|
616
637
|
setCookie(event, name, "", {
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { withoutTrailingSlash, withoutBase, getQuery as getQuery$1, decode, decodePath, withLeadingSlash, parseURL, joinURL } from 'ufo';
|
|
2
|
-
import { parse as parse$1, serialize } from 'cookie-es';
|
|
3
|
-
import { objectHash } from 'ohash';
|
|
2
|
+
import { parse as parse$1, serialize, parseSetCookie } from 'cookie-es';
|
|
4
3
|
import { createRouter as createRouter$1, toRouteMatcher } from 'radix3';
|
|
5
4
|
import destr from 'destr';
|
|
6
5
|
import { defu } from 'defu';
|
|
@@ -586,24 +585,46 @@ function sanitizeStatusCode(statusCode, defaultStatusCode = 200) {
|
|
|
586
585
|
return statusCode;
|
|
587
586
|
}
|
|
588
587
|
|
|
588
|
+
function getDistinctCookieKey(name, opts) {
|
|
589
|
+
return [
|
|
590
|
+
name,
|
|
591
|
+
opts.domain || "",
|
|
592
|
+
opts.path || "/",
|
|
593
|
+
Boolean(opts.secure),
|
|
594
|
+
Boolean(opts.httpOnly),
|
|
595
|
+
Boolean(opts.sameSite)
|
|
596
|
+
].join(";");
|
|
597
|
+
}
|
|
598
|
+
|
|
589
599
|
function parseCookies(event) {
|
|
590
600
|
return parse$1(event.node.req.headers.cookie || "");
|
|
591
601
|
}
|
|
592
602
|
function getCookie(event, name) {
|
|
593
603
|
return parseCookies(event)[name];
|
|
594
604
|
}
|
|
595
|
-
function setCookie(event, name, value, serializeOptions) {
|
|
596
|
-
serializeOptions
|
|
597
|
-
|
|
598
|
-
let setCookies = event.node.res.getHeader("set-cookie");
|
|
599
|
-
if (!Array.isArray(setCookies)) {
|
|
600
|
-
setCookies = [setCookies];
|
|
605
|
+
function setCookie(event, name, value, serializeOptions = {}) {
|
|
606
|
+
if (!serializeOptions.path) {
|
|
607
|
+
serializeOptions = { path: "/", ...serializeOptions };
|
|
601
608
|
}
|
|
602
|
-
const
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
609
|
+
const newCookie = serialize(name, value, serializeOptions);
|
|
610
|
+
const currentCookies = splitCookiesString(
|
|
611
|
+
event.node.res.getHeader("set-cookie")
|
|
612
|
+
);
|
|
613
|
+
if (currentCookies.length === 0) {
|
|
614
|
+
event.node.res.setHeader("set-cookie", newCookie);
|
|
615
|
+
return;
|
|
616
|
+
}
|
|
617
|
+
const newCookieKey = getDistinctCookieKey(name, serializeOptions);
|
|
618
|
+
event.node.res.removeHeader("set-cookie");
|
|
619
|
+
for (const cookie of currentCookies) {
|
|
620
|
+
const parsed = parseSetCookie(cookie);
|
|
621
|
+
const key = getDistinctCookieKey(parsed.name, parsed);
|
|
622
|
+
if (key === newCookieKey) {
|
|
623
|
+
continue;
|
|
624
|
+
}
|
|
625
|
+
event.node.res.appendHeader("set-cookie", cookie);
|
|
626
|
+
}
|
|
627
|
+
event.node.res.appendHeader("set-cookie", newCookie);
|
|
607
628
|
}
|
|
608
629
|
function deleteCookie(event, name, serializeOptions) {
|
|
609
630
|
setCookie(event, name, "", {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "h3",
|
|
3
|
-
"version": "1.15.
|
|
3
|
+
"version": "1.15.1",
|
|
4
4
|
"description": "Minimal H(TTP) framework built for high performance and portability.",
|
|
5
5
|
"repository": "unjs/h3",
|
|
6
6
|
"license": "MIT",
|
|
@@ -39,7 +39,6 @@
|
|
|
39
39
|
"destr": "^2.0.3",
|
|
40
40
|
"iron-webcrypto": "^1.2.1",
|
|
41
41
|
"node-mock-http": "^1.0.0",
|
|
42
|
-
"ohash": "^1.1.4",
|
|
43
42
|
"radix3": "^1.1.2",
|
|
44
43
|
"ufo": "^1.5.4",
|
|
45
44
|
"uncrypto": "^0.1.3"
|