@hono/node-server 1.15.0 → 1.17.0
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/README.md +14 -1
- package/dist/index.js +67 -8
- package/dist/index.mjs +67 -8
- package/dist/listener.d.mts +1 -0
- package/dist/listener.d.ts +1 -0
- package/dist/listener.js +63 -7
- package/dist/listener.mjs +65 -7
- package/dist/request.d.mts +5 -1
- package/dist/request.d.ts +5 -1
- package/dist/request.js +22 -2
- package/dist/request.mjs +20 -1
- package/dist/serve-static.js +18 -22
- package/dist/serve-static.mjs +18 -22
- package/dist/server.js +67 -8
- package/dist/server.mjs +67 -8
- package/dist/types.d.mts +1 -0
- package/dist/types.d.ts +1 -0
- package/dist/vercel.js +65 -7
- package/dist/vercel.mjs +65 -7
- package/package.json +2 -2
package/dist/vercel.mjs
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
// src/listener.ts
|
|
2
|
+
import { Http2ServerRequest as Http2ServerRequest2 } from "http2";
|
|
3
|
+
|
|
1
4
|
// src/request.ts
|
|
2
5
|
import { Http2ServerRequest } from "http2";
|
|
3
6
|
import { Readable } from "stream";
|
|
@@ -26,6 +29,7 @@ var Request = class extends GlobalRequest {
|
|
|
26
29
|
super(input, options);
|
|
27
30
|
}
|
|
28
31
|
};
|
|
32
|
+
var wrapBodyStream = Symbol("wrapBodyStream");
|
|
29
33
|
var newRequestFromIncoming = (method, url, incoming, abortController) => {
|
|
30
34
|
const headerRecord = [];
|
|
31
35
|
const rawHeaders = incoming.rawHeaders;
|
|
@@ -59,6 +63,23 @@ var newRequestFromIncoming = (method, url, incoming, abortController) => {
|
|
|
59
63
|
controller.close();
|
|
60
64
|
}
|
|
61
65
|
});
|
|
66
|
+
} else if (incoming[wrapBodyStream]) {
|
|
67
|
+
let reader;
|
|
68
|
+
init.body = new ReadableStream({
|
|
69
|
+
async pull(controller) {
|
|
70
|
+
try {
|
|
71
|
+
reader ||= Readable.toWeb(incoming).getReader();
|
|
72
|
+
const { done, value } = await reader.read();
|
|
73
|
+
if (done) {
|
|
74
|
+
controller.close();
|
|
75
|
+
} else {
|
|
76
|
+
controller.enqueue(value);
|
|
77
|
+
}
|
|
78
|
+
} catch (error) {
|
|
79
|
+
controller.error(error);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
});
|
|
62
83
|
} else {
|
|
63
84
|
init.body = Readable.toWeb(incoming);
|
|
64
85
|
}
|
|
@@ -307,6 +328,7 @@ global.fetch = (info, init) => {
|
|
|
307
328
|
};
|
|
308
329
|
|
|
309
330
|
// src/listener.ts
|
|
331
|
+
var outgoingEnded = Symbol("outgoingEnded");
|
|
310
332
|
var regBuffer = /^no$/i;
|
|
311
333
|
var regContentType = /^(application\/json\b|text\/(?!event-stream\b))/i;
|
|
312
334
|
var handleRequestError = () => new Response(null, {
|
|
@@ -352,10 +374,12 @@ var responseViaCache = async (res, outgoing) => {
|
|
|
352
374
|
outgoing.end(new Uint8Array(await body.arrayBuffer()));
|
|
353
375
|
} else {
|
|
354
376
|
flushHeaders(outgoing);
|
|
355
|
-
|
|
377
|
+
await writeFromReadableStream(body, outgoing)?.catch(
|
|
356
378
|
(e) => handleResponseError(e, outgoing)
|
|
357
379
|
);
|
|
358
380
|
}
|
|
381
|
+
;
|
|
382
|
+
outgoing[outgoingEnded]?.();
|
|
359
383
|
};
|
|
360
384
|
var responseViaResponseObject = async (res, outgoing, options = {}) => {
|
|
361
385
|
if (res instanceof Promise) {
|
|
@@ -401,8 +425,11 @@ var responseViaResponseObject = async (res, outgoing, options = {}) => {
|
|
|
401
425
|
outgoing.writeHead(res.status, resHeaderRecord);
|
|
402
426
|
outgoing.end();
|
|
403
427
|
}
|
|
428
|
+
;
|
|
429
|
+
outgoing[outgoingEnded]?.();
|
|
404
430
|
};
|
|
405
431
|
var getRequestListener = (fetchCallback, options = {}) => {
|
|
432
|
+
const autoCleanupIncoming = options.autoCleanupIncoming ?? true;
|
|
406
433
|
if (options.overrideGlobalObjects !== false && global.Request !== Request) {
|
|
407
434
|
Object.defineProperty(global, "Request", {
|
|
408
435
|
value: Request
|
|
@@ -415,15 +442,46 @@ var getRequestListener = (fetchCallback, options = {}) => {
|
|
|
415
442
|
let res, req;
|
|
416
443
|
try {
|
|
417
444
|
req = newRequest(incoming, options.hostname);
|
|
445
|
+
let incomingEnded = !autoCleanupIncoming || incoming.method === "GET" || incoming.method === "HEAD";
|
|
446
|
+
if (!incomingEnded) {
|
|
447
|
+
;
|
|
448
|
+
incoming[wrapBodyStream] = true;
|
|
449
|
+
incoming.on("end", () => {
|
|
450
|
+
incomingEnded = true;
|
|
451
|
+
});
|
|
452
|
+
if (incoming instanceof Http2ServerRequest2) {
|
|
453
|
+
;
|
|
454
|
+
outgoing[outgoingEnded] = () => {
|
|
455
|
+
if (!incomingEnded) {
|
|
456
|
+
setTimeout(() => {
|
|
457
|
+
if (!incomingEnded) {
|
|
458
|
+
setTimeout(() => {
|
|
459
|
+
incoming.destroy();
|
|
460
|
+
outgoing.destroy();
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
}
|
|
418
468
|
outgoing.on("close", () => {
|
|
419
469
|
const abortController = req[abortControllerKey];
|
|
420
|
-
if (
|
|
421
|
-
|
|
470
|
+
if (abortController) {
|
|
471
|
+
if (incoming.errored) {
|
|
472
|
+
req[abortControllerKey].abort(incoming.errored.toString());
|
|
473
|
+
} else if (!outgoing.writableFinished) {
|
|
474
|
+
req[abortControllerKey].abort("Client connection prematurely closed.");
|
|
475
|
+
}
|
|
422
476
|
}
|
|
423
|
-
if (
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
477
|
+
if (!incomingEnded) {
|
|
478
|
+
setTimeout(() => {
|
|
479
|
+
if (!incomingEnded) {
|
|
480
|
+
setTimeout(() => {
|
|
481
|
+
incoming.destroy();
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
});
|
|
427
485
|
}
|
|
428
486
|
});
|
|
429
487
|
res = fetchCallback(req, { incoming, outgoing });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hono/node-server",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.17.0",
|
|
4
4
|
"description": "Node.js Adapter for Hono",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
}
|
|
55
55
|
},
|
|
56
56
|
"scripts": {
|
|
57
|
-
"test": "node --expose-gc
|
|
57
|
+
"test": "node --expose-gc node_modules/jest/bin/jest.js",
|
|
58
58
|
"build": "tsup --external hono",
|
|
59
59
|
"watch": "tsup --watch",
|
|
60
60
|
"postbuild": "publint",
|