h3 0.8.1 → 0.8.2
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 +31 -9
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +31 -9
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -284,21 +284,43 @@ function sendStream(event, data) {
|
|
|
284
284
|
data.on("error", (error) => reject(createError(error)));
|
|
285
285
|
});
|
|
286
286
|
}
|
|
287
|
-
|
|
287
|
+
const noop = () => {
|
|
288
|
+
};
|
|
289
|
+
function writeEarlyHints(event, hints, cb = noop) {
|
|
288
290
|
if (!event.res.socket && !("writeEarlyHints" in event.res)) {
|
|
289
|
-
|
|
290
|
-
callback();
|
|
291
|
-
}
|
|
291
|
+
cb();
|
|
292
292
|
return;
|
|
293
293
|
}
|
|
294
|
+
if (typeof hints === "string" || Array.isArray(hints)) {
|
|
295
|
+
hints = { link: hints };
|
|
296
|
+
}
|
|
297
|
+
if (hints.link) {
|
|
298
|
+
hints.link = Array.isArray(hints.link) ? hints.link : hints.link.split(",");
|
|
299
|
+
hints.link = hints.link.map((l) => l.trim().replace(/; crossorigin/g, ""));
|
|
300
|
+
}
|
|
294
301
|
if ("writeEarlyHints" in event.res) {
|
|
295
|
-
return event.res.writeEarlyHints(
|
|
302
|
+
return event.res.writeEarlyHints(hints, cb);
|
|
303
|
+
}
|
|
304
|
+
const headers = Object.entries(hints).map((e) => [e[0].toLowerCase(), e[1]]);
|
|
305
|
+
if (!headers.length) {
|
|
306
|
+
cb();
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
let hint = "HTTP/1.1 103 Early Hints";
|
|
310
|
+
if (hints.link) {
|
|
311
|
+
hint += `\r
|
|
312
|
+
Link: ${hints.link.join("\r\n")}`;
|
|
313
|
+
}
|
|
314
|
+
for (const [header, value] of headers) {
|
|
315
|
+
if (header === "link") {
|
|
316
|
+
continue;
|
|
317
|
+
}
|
|
318
|
+
hint += `\r
|
|
319
|
+
${header}: ${value}`;
|
|
296
320
|
}
|
|
297
|
-
|
|
298
|
-
event.res.socket.write(`HTTP/1.1 103 Early Hints\r
|
|
299
|
-
Link: ${_links.join("\r\n")}\r
|
|
321
|
+
event.res.socket.write(`${hint}\r
|
|
300
322
|
\r
|
|
301
|
-
`, "utf-8",
|
|
323
|
+
`, "utf-8", cb);
|
|
302
324
|
}
|
|
303
325
|
|
|
304
326
|
function parseCookies(event) {
|
package/dist/index.d.ts
CHANGED
|
@@ -270,7 +270,7 @@ declare function appendResponseHeader(event: H3Event, name: string, value: strin
|
|
|
270
270
|
declare const appendHeader: typeof appendResponseHeader;
|
|
271
271
|
declare function isStream(data: any): any;
|
|
272
272
|
declare function sendStream(event: H3Event, data: any): Promise<void>;
|
|
273
|
-
declare function writeEarlyHints(event: H3Event,
|
|
273
|
+
declare function writeEarlyHints(event: H3Event, hints: string | string[] | Record<string, string | string[]>, cb?: () => void): void;
|
|
274
274
|
|
|
275
275
|
declare type RouterMethod = Lowercase<HTTPMethod>;
|
|
276
276
|
declare type RouterUse = (path: string, handler: EventHandler, method?: RouterMethod | RouterMethod[]) => Router;
|
package/dist/index.mjs
CHANGED
|
@@ -282,21 +282,43 @@ function sendStream(event, data) {
|
|
|
282
282
|
data.on("error", (error) => reject(createError(error)));
|
|
283
283
|
});
|
|
284
284
|
}
|
|
285
|
-
|
|
285
|
+
const noop = () => {
|
|
286
|
+
};
|
|
287
|
+
function writeEarlyHints(event, hints, cb = noop) {
|
|
286
288
|
if (!event.res.socket && !("writeEarlyHints" in event.res)) {
|
|
287
|
-
|
|
288
|
-
callback();
|
|
289
|
-
}
|
|
289
|
+
cb();
|
|
290
290
|
return;
|
|
291
291
|
}
|
|
292
|
+
if (typeof hints === "string" || Array.isArray(hints)) {
|
|
293
|
+
hints = { link: hints };
|
|
294
|
+
}
|
|
295
|
+
if (hints.link) {
|
|
296
|
+
hints.link = Array.isArray(hints.link) ? hints.link : hints.link.split(",");
|
|
297
|
+
hints.link = hints.link.map((l) => l.trim().replace(/; crossorigin/g, ""));
|
|
298
|
+
}
|
|
292
299
|
if ("writeEarlyHints" in event.res) {
|
|
293
|
-
return event.res.writeEarlyHints(
|
|
300
|
+
return event.res.writeEarlyHints(hints, cb);
|
|
301
|
+
}
|
|
302
|
+
const headers = Object.entries(hints).map((e) => [e[0].toLowerCase(), e[1]]);
|
|
303
|
+
if (!headers.length) {
|
|
304
|
+
cb();
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
let hint = "HTTP/1.1 103 Early Hints";
|
|
308
|
+
if (hints.link) {
|
|
309
|
+
hint += `\r
|
|
310
|
+
Link: ${hints.link.join("\r\n")}`;
|
|
311
|
+
}
|
|
312
|
+
for (const [header, value] of headers) {
|
|
313
|
+
if (header === "link") {
|
|
314
|
+
continue;
|
|
315
|
+
}
|
|
316
|
+
hint += `\r
|
|
317
|
+
${header}: ${value}`;
|
|
294
318
|
}
|
|
295
|
-
|
|
296
|
-
event.res.socket.write(`HTTP/1.1 103 Early Hints\r
|
|
297
|
-
Link: ${_links.join("\r\n")}\r
|
|
319
|
+
event.res.socket.write(`${hint}\r
|
|
298
320
|
\r
|
|
299
|
-
`, "utf-8",
|
|
321
|
+
`, "utf-8", cb);
|
|
300
322
|
}
|
|
301
323
|
|
|
302
324
|
function parseCookies(event) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "h3",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.2",
|
|
4
4
|
"description": "Tiny JavaScript Server",
|
|
5
5
|
"repository": "unjs/h3",
|
|
6
6
|
"license": "MIT",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"cookie-es": "^0.5.0",
|
|
24
24
|
"destr": "^1.1.1",
|
|
25
25
|
"radix3": "^0.2.1",
|
|
26
|
-
"ufo": "^0.8.
|
|
26
|
+
"ufo": "^0.8.6"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"0x": "^5.4.1",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"@types/supertest": "^2.0.12",
|
|
34
34
|
"@vitest/coverage-c8": "^0.24.3",
|
|
35
35
|
"autocannon": "^7.10.0",
|
|
36
|
-
"changelogen": "^0.3.
|
|
36
|
+
"changelogen": "^0.3.5",
|
|
37
37
|
"connect": "^3.7.0",
|
|
38
38
|
"eslint": "^8.25.0",
|
|
39
39
|
"express": "^4.18.2",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"listhen": "^0.3.4",
|
|
43
43
|
"supertest": "^6.3.0",
|
|
44
44
|
"typescript": "^4.8.4",
|
|
45
|
-
"unbuild": "^0.9.
|
|
45
|
+
"unbuild": "^0.9.4",
|
|
46
46
|
"vitest": "^0.24.3"
|
|
47
47
|
},
|
|
48
48
|
"packageManager": "pnpm@7.13.4",
|