@hono/node-server 1.19.10 → 1.19.12

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.js CHANGED
@@ -258,15 +258,17 @@ var Response2 = class _Response {
258
258
  this.#init = init;
259
259
  }
260
260
  if (typeof body === "string" || typeof body?.getReader !== "undefined" || body instanceof Blob || body instanceof Uint8Array) {
261
- headers ||= init?.headers || { "content-type": "text/plain; charset=UTF-8" };
262
- this[cacheKey] = [init?.status || 200, body, headers];
261
+ ;
262
+ this[cacheKey] = [init?.status || 200, body, headers || init?.headers];
263
263
  }
264
264
  }
265
265
  get headers() {
266
266
  const cache = this[cacheKey];
267
267
  if (cache) {
268
268
  if (!(cache[2] instanceof Headers)) {
269
- cache[2] = new Headers(cache[2]);
269
+ cache[2] = new Headers(
270
+ cache[2] || { "content-type": "text/plain; charset=UTF-8" }
271
+ );
270
272
  }
271
273
  return cache[2];
272
274
  }
@@ -374,6 +376,50 @@ if (typeof global.crypto === "undefined") {
374
376
 
375
377
  // src/listener.ts
376
378
  var outgoingEnded = Symbol("outgoingEnded");
379
+ var incomingDraining = Symbol("incomingDraining");
380
+ var DRAIN_TIMEOUT_MS = 500;
381
+ var MAX_DRAIN_BYTES = 64 * 1024 * 1024;
382
+ var drainIncoming = (incoming) => {
383
+ const incomingWithDrainState = incoming;
384
+ if (incoming.destroyed || incomingWithDrainState[incomingDraining]) {
385
+ return;
386
+ }
387
+ incomingWithDrainState[incomingDraining] = true;
388
+ if (incoming instanceof import_node_http22.Http2ServerRequest) {
389
+ try {
390
+ ;
391
+ incoming.stream?.close?.(import_node_http22.constants.NGHTTP2_NO_ERROR);
392
+ } catch {
393
+ }
394
+ return;
395
+ }
396
+ let bytesRead = 0;
397
+ const cleanup = () => {
398
+ clearTimeout(timer);
399
+ incoming.off("data", onData);
400
+ incoming.off("end", cleanup);
401
+ incoming.off("error", cleanup);
402
+ };
403
+ const forceClose = () => {
404
+ cleanup();
405
+ const socket = incoming.socket;
406
+ if (socket && !socket.destroyed) {
407
+ socket.destroySoon();
408
+ }
409
+ };
410
+ const timer = setTimeout(forceClose, DRAIN_TIMEOUT_MS);
411
+ timer.unref?.();
412
+ const onData = (chunk) => {
413
+ bytesRead += chunk.length;
414
+ if (bytesRead > MAX_DRAIN_BYTES) {
415
+ forceClose();
416
+ }
417
+ };
418
+ incoming.on("data", onData);
419
+ incoming.on("end", cleanup);
420
+ incoming.on("error", cleanup);
421
+ incoming.resume();
422
+ };
377
423
  var handleRequestError = () => new Response(null, {
378
424
  status: 400
379
425
  });
@@ -400,15 +446,32 @@ var flushHeaders = (outgoing) => {
400
446
  };
401
447
  var responseViaCache = async (res, outgoing) => {
402
448
  let [status, body, header] = res[cacheKey];
403
- if (header instanceof Headers) {
449
+ let hasContentLength = false;
450
+ if (!header) {
451
+ header = { "content-type": "text/plain; charset=UTF-8" };
452
+ } else if (header instanceof Headers) {
453
+ hasContentLength = header.has("content-length");
404
454
  header = buildOutgoingHttpHeaders(header);
455
+ } else if (Array.isArray(header)) {
456
+ const headerObj = new Headers(header);
457
+ hasContentLength = headerObj.has("content-length");
458
+ header = buildOutgoingHttpHeaders(headerObj);
459
+ } else {
460
+ for (const key in header) {
461
+ if (key.length === 14 && key.toLowerCase() === "content-length") {
462
+ hasContentLength = true;
463
+ break;
464
+ }
465
+ }
405
466
  }
406
- if (typeof body === "string") {
407
- header["Content-Length"] = Buffer.byteLength(body);
408
- } else if (body instanceof Uint8Array) {
409
- header["Content-Length"] = body.byteLength;
410
- } else if (body instanceof Blob) {
411
- header["Content-Length"] = body.size;
467
+ if (!hasContentLength) {
468
+ if (typeof body === "string") {
469
+ header["Content-Length"] = Buffer.byteLength(body);
470
+ } else if (body instanceof Uint8Array) {
471
+ header["Content-Length"] = body.byteLength;
472
+ } else if (body instanceof Blob) {
473
+ header["Content-Length"] = body.size;
474
+ }
412
475
  }
413
476
  outgoing.writeHead(status, header);
414
477
  if (typeof body === "string" || body instanceof Uint8Array) {
@@ -528,14 +591,18 @@ var getRequestListener = (fetchCallback, options = {}) => {
528
591
  setTimeout(() => {
529
592
  if (!incomingEnded) {
530
593
  setTimeout(() => {
531
- incoming.destroy();
532
- outgoing.destroy();
594
+ drainIncoming(incoming);
533
595
  });
534
596
  }
535
597
  });
536
598
  }
537
599
  };
538
600
  }
601
+ outgoing.on("finish", () => {
602
+ if (!incomingEnded) {
603
+ drainIncoming(incoming);
604
+ }
605
+ });
539
606
  }
540
607
  outgoing.on("close", () => {
541
608
  const abortController = req[abortControllerKey];
@@ -550,7 +617,7 @@ var getRequestListener = (fetchCallback, options = {}) => {
550
617
  setTimeout(() => {
551
618
  if (!incomingEnded) {
552
619
  setTimeout(() => {
553
- incoming.destroy();
620
+ drainIncoming(incoming);
554
621
  });
555
622
  }
556
623
  });
package/dist/index.mjs CHANGED
@@ -2,7 +2,7 @@
2
2
  import { createServer as createServerHTTP } from "http";
3
3
 
4
4
  // src/listener.ts
5
- import { Http2ServerRequest as Http2ServerRequest2 } from "http2";
5
+ import { Http2ServerRequest as Http2ServerRequest2, constants as h2constants } from "http2";
6
6
 
7
7
  // src/request.ts
8
8
  import { Http2ServerRequest } from "http2";
@@ -219,15 +219,17 @@ var Response2 = class _Response {
219
219
  this.#init = init;
220
220
  }
221
221
  if (typeof body === "string" || typeof body?.getReader !== "undefined" || body instanceof Blob || body instanceof Uint8Array) {
222
- headers ||= init?.headers || { "content-type": "text/plain; charset=UTF-8" };
223
- this[cacheKey] = [init?.status || 200, body, headers];
222
+ ;
223
+ this[cacheKey] = [init?.status || 200, body, headers || init?.headers];
224
224
  }
225
225
  }
226
226
  get headers() {
227
227
  const cache = this[cacheKey];
228
228
  if (cache) {
229
229
  if (!(cache[2] instanceof Headers)) {
230
- cache[2] = new Headers(cache[2]);
230
+ cache[2] = new Headers(
231
+ cache[2] || { "content-type": "text/plain; charset=UTF-8" }
232
+ );
231
233
  }
232
234
  return cache[2];
233
235
  }
@@ -335,6 +337,50 @@ if (typeof global.crypto === "undefined") {
335
337
 
336
338
  // src/listener.ts
337
339
  var outgoingEnded = Symbol("outgoingEnded");
340
+ var incomingDraining = Symbol("incomingDraining");
341
+ var DRAIN_TIMEOUT_MS = 500;
342
+ var MAX_DRAIN_BYTES = 64 * 1024 * 1024;
343
+ var drainIncoming = (incoming) => {
344
+ const incomingWithDrainState = incoming;
345
+ if (incoming.destroyed || incomingWithDrainState[incomingDraining]) {
346
+ return;
347
+ }
348
+ incomingWithDrainState[incomingDraining] = true;
349
+ if (incoming instanceof Http2ServerRequest2) {
350
+ try {
351
+ ;
352
+ incoming.stream?.close?.(h2constants.NGHTTP2_NO_ERROR);
353
+ } catch {
354
+ }
355
+ return;
356
+ }
357
+ let bytesRead = 0;
358
+ const cleanup = () => {
359
+ clearTimeout(timer);
360
+ incoming.off("data", onData);
361
+ incoming.off("end", cleanup);
362
+ incoming.off("error", cleanup);
363
+ };
364
+ const forceClose = () => {
365
+ cleanup();
366
+ const socket = incoming.socket;
367
+ if (socket && !socket.destroyed) {
368
+ socket.destroySoon();
369
+ }
370
+ };
371
+ const timer = setTimeout(forceClose, DRAIN_TIMEOUT_MS);
372
+ timer.unref?.();
373
+ const onData = (chunk) => {
374
+ bytesRead += chunk.length;
375
+ if (bytesRead > MAX_DRAIN_BYTES) {
376
+ forceClose();
377
+ }
378
+ };
379
+ incoming.on("data", onData);
380
+ incoming.on("end", cleanup);
381
+ incoming.on("error", cleanup);
382
+ incoming.resume();
383
+ };
338
384
  var handleRequestError = () => new Response(null, {
339
385
  status: 400
340
386
  });
@@ -361,15 +407,32 @@ var flushHeaders = (outgoing) => {
361
407
  };
362
408
  var responseViaCache = async (res, outgoing) => {
363
409
  let [status, body, header] = res[cacheKey];
364
- if (header instanceof Headers) {
410
+ let hasContentLength = false;
411
+ if (!header) {
412
+ header = { "content-type": "text/plain; charset=UTF-8" };
413
+ } else if (header instanceof Headers) {
414
+ hasContentLength = header.has("content-length");
365
415
  header = buildOutgoingHttpHeaders(header);
416
+ } else if (Array.isArray(header)) {
417
+ const headerObj = new Headers(header);
418
+ hasContentLength = headerObj.has("content-length");
419
+ header = buildOutgoingHttpHeaders(headerObj);
420
+ } else {
421
+ for (const key in header) {
422
+ if (key.length === 14 && key.toLowerCase() === "content-length") {
423
+ hasContentLength = true;
424
+ break;
425
+ }
426
+ }
366
427
  }
367
- if (typeof body === "string") {
368
- header["Content-Length"] = Buffer.byteLength(body);
369
- } else if (body instanceof Uint8Array) {
370
- header["Content-Length"] = body.byteLength;
371
- } else if (body instanceof Blob) {
372
- header["Content-Length"] = body.size;
428
+ if (!hasContentLength) {
429
+ if (typeof body === "string") {
430
+ header["Content-Length"] = Buffer.byteLength(body);
431
+ } else if (body instanceof Uint8Array) {
432
+ header["Content-Length"] = body.byteLength;
433
+ } else if (body instanceof Blob) {
434
+ header["Content-Length"] = body.size;
435
+ }
373
436
  }
374
437
  outgoing.writeHead(status, header);
375
438
  if (typeof body === "string" || body instanceof Uint8Array) {
@@ -489,14 +552,18 @@ var getRequestListener = (fetchCallback, options = {}) => {
489
552
  setTimeout(() => {
490
553
  if (!incomingEnded) {
491
554
  setTimeout(() => {
492
- incoming.destroy();
493
- outgoing.destroy();
555
+ drainIncoming(incoming);
494
556
  });
495
557
  }
496
558
  });
497
559
  }
498
560
  };
499
561
  }
562
+ outgoing.on("finish", () => {
563
+ if (!incomingEnded) {
564
+ drainIncoming(incoming);
565
+ }
566
+ });
500
567
  }
501
568
  outgoing.on("close", () => {
502
569
  const abortController = req[abortControllerKey];
@@ -511,7 +578,7 @@ var getRequestListener = (fetchCallback, options = {}) => {
511
578
  setTimeout(() => {
512
579
  if (!incomingEnded) {
513
580
  setTimeout(() => {
514
- incoming.destroy();
581
+ drainIncoming(incoming);
515
582
  });
516
583
  }
517
584
  });
package/dist/listener.js CHANGED
@@ -250,15 +250,17 @@ var Response2 = class _Response {
250
250
  this.#init = init;
251
251
  }
252
252
  if (typeof body === "string" || typeof body?.getReader !== "undefined" || body instanceof Blob || body instanceof Uint8Array) {
253
- headers ||= init?.headers || { "content-type": "text/plain; charset=UTF-8" };
254
- this[cacheKey] = [init?.status || 200, body, headers];
253
+ ;
254
+ this[cacheKey] = [init?.status || 200, body, headers || init?.headers];
255
255
  }
256
256
  }
257
257
  get headers() {
258
258
  const cache = this[cacheKey];
259
259
  if (cache) {
260
260
  if (!(cache[2] instanceof Headers)) {
261
- cache[2] = new Headers(cache[2]);
261
+ cache[2] = new Headers(
262
+ cache[2] || { "content-type": "text/plain; charset=UTF-8" }
263
+ );
262
264
  }
263
265
  return cache[2];
264
266
  }
@@ -366,6 +368,50 @@ if (typeof global.crypto === "undefined") {
366
368
 
367
369
  // src/listener.ts
368
370
  var outgoingEnded = Symbol("outgoingEnded");
371
+ var incomingDraining = Symbol("incomingDraining");
372
+ var DRAIN_TIMEOUT_MS = 500;
373
+ var MAX_DRAIN_BYTES = 64 * 1024 * 1024;
374
+ var drainIncoming = (incoming) => {
375
+ const incomingWithDrainState = incoming;
376
+ if (incoming.destroyed || incomingWithDrainState[incomingDraining]) {
377
+ return;
378
+ }
379
+ incomingWithDrainState[incomingDraining] = true;
380
+ if (incoming instanceof import_node_http22.Http2ServerRequest) {
381
+ try {
382
+ ;
383
+ incoming.stream?.close?.(import_node_http22.constants.NGHTTP2_NO_ERROR);
384
+ } catch {
385
+ }
386
+ return;
387
+ }
388
+ let bytesRead = 0;
389
+ const cleanup = () => {
390
+ clearTimeout(timer);
391
+ incoming.off("data", onData);
392
+ incoming.off("end", cleanup);
393
+ incoming.off("error", cleanup);
394
+ };
395
+ const forceClose = () => {
396
+ cleanup();
397
+ const socket = incoming.socket;
398
+ if (socket && !socket.destroyed) {
399
+ socket.destroySoon();
400
+ }
401
+ };
402
+ const timer = setTimeout(forceClose, DRAIN_TIMEOUT_MS);
403
+ timer.unref?.();
404
+ const onData = (chunk) => {
405
+ bytesRead += chunk.length;
406
+ if (bytesRead > MAX_DRAIN_BYTES) {
407
+ forceClose();
408
+ }
409
+ };
410
+ incoming.on("data", onData);
411
+ incoming.on("end", cleanup);
412
+ incoming.on("error", cleanup);
413
+ incoming.resume();
414
+ };
369
415
  var handleRequestError = () => new Response(null, {
370
416
  status: 400
371
417
  });
@@ -392,15 +438,32 @@ var flushHeaders = (outgoing) => {
392
438
  };
393
439
  var responseViaCache = async (res, outgoing) => {
394
440
  let [status, body, header] = res[cacheKey];
395
- if (header instanceof Headers) {
441
+ let hasContentLength = false;
442
+ if (!header) {
443
+ header = { "content-type": "text/plain; charset=UTF-8" };
444
+ } else if (header instanceof Headers) {
445
+ hasContentLength = header.has("content-length");
396
446
  header = buildOutgoingHttpHeaders(header);
447
+ } else if (Array.isArray(header)) {
448
+ const headerObj = new Headers(header);
449
+ hasContentLength = headerObj.has("content-length");
450
+ header = buildOutgoingHttpHeaders(headerObj);
451
+ } else {
452
+ for (const key in header) {
453
+ if (key.length === 14 && key.toLowerCase() === "content-length") {
454
+ hasContentLength = true;
455
+ break;
456
+ }
457
+ }
397
458
  }
398
- if (typeof body === "string") {
399
- header["Content-Length"] = Buffer.byteLength(body);
400
- } else if (body instanceof Uint8Array) {
401
- header["Content-Length"] = body.byteLength;
402
- } else if (body instanceof Blob) {
403
- header["Content-Length"] = body.size;
459
+ if (!hasContentLength) {
460
+ if (typeof body === "string") {
461
+ header["Content-Length"] = Buffer.byteLength(body);
462
+ } else if (body instanceof Uint8Array) {
463
+ header["Content-Length"] = body.byteLength;
464
+ } else if (body instanceof Blob) {
465
+ header["Content-Length"] = body.size;
466
+ }
404
467
  }
405
468
  outgoing.writeHead(status, header);
406
469
  if (typeof body === "string" || body instanceof Uint8Array) {
@@ -520,14 +583,18 @@ var getRequestListener = (fetchCallback, options = {}) => {
520
583
  setTimeout(() => {
521
584
  if (!incomingEnded) {
522
585
  setTimeout(() => {
523
- incoming.destroy();
524
- outgoing.destroy();
586
+ drainIncoming(incoming);
525
587
  });
526
588
  }
527
589
  });
528
590
  }
529
591
  };
530
592
  }
593
+ outgoing.on("finish", () => {
594
+ if (!incomingEnded) {
595
+ drainIncoming(incoming);
596
+ }
597
+ });
531
598
  }
532
599
  outgoing.on("close", () => {
533
600
  const abortController = req[abortControllerKey];
@@ -542,7 +609,7 @@ var getRequestListener = (fetchCallback, options = {}) => {
542
609
  setTimeout(() => {
543
610
  if (!incomingEnded) {
544
611
  setTimeout(() => {
545
- incoming.destroy();
612
+ drainIncoming(incoming);
546
613
  });
547
614
  }
548
615
  });
package/dist/listener.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/listener.ts
2
- import { Http2ServerRequest as Http2ServerRequest2 } from "http2";
2
+ import { Http2ServerRequest as Http2ServerRequest2, constants as h2constants } from "http2";
3
3
 
4
4
  // src/request.ts
5
5
  import { Http2ServerRequest } from "http2";
@@ -216,15 +216,17 @@ var Response2 = class _Response {
216
216
  this.#init = init;
217
217
  }
218
218
  if (typeof body === "string" || typeof body?.getReader !== "undefined" || body instanceof Blob || body instanceof Uint8Array) {
219
- headers ||= init?.headers || { "content-type": "text/plain; charset=UTF-8" };
220
- this[cacheKey] = [init?.status || 200, body, headers];
219
+ ;
220
+ this[cacheKey] = [init?.status || 200, body, headers || init?.headers];
221
221
  }
222
222
  }
223
223
  get headers() {
224
224
  const cache = this[cacheKey];
225
225
  if (cache) {
226
226
  if (!(cache[2] instanceof Headers)) {
227
- cache[2] = new Headers(cache[2]);
227
+ cache[2] = new Headers(
228
+ cache[2] || { "content-type": "text/plain; charset=UTF-8" }
229
+ );
228
230
  }
229
231
  return cache[2];
230
232
  }
@@ -332,6 +334,50 @@ if (typeof global.crypto === "undefined") {
332
334
 
333
335
  // src/listener.ts
334
336
  var outgoingEnded = Symbol("outgoingEnded");
337
+ var incomingDraining = Symbol("incomingDraining");
338
+ var DRAIN_TIMEOUT_MS = 500;
339
+ var MAX_DRAIN_BYTES = 64 * 1024 * 1024;
340
+ var drainIncoming = (incoming) => {
341
+ const incomingWithDrainState = incoming;
342
+ if (incoming.destroyed || incomingWithDrainState[incomingDraining]) {
343
+ return;
344
+ }
345
+ incomingWithDrainState[incomingDraining] = true;
346
+ if (incoming instanceof Http2ServerRequest2) {
347
+ try {
348
+ ;
349
+ incoming.stream?.close?.(h2constants.NGHTTP2_NO_ERROR);
350
+ } catch {
351
+ }
352
+ return;
353
+ }
354
+ let bytesRead = 0;
355
+ const cleanup = () => {
356
+ clearTimeout(timer);
357
+ incoming.off("data", onData);
358
+ incoming.off("end", cleanup);
359
+ incoming.off("error", cleanup);
360
+ };
361
+ const forceClose = () => {
362
+ cleanup();
363
+ const socket = incoming.socket;
364
+ if (socket && !socket.destroyed) {
365
+ socket.destroySoon();
366
+ }
367
+ };
368
+ const timer = setTimeout(forceClose, DRAIN_TIMEOUT_MS);
369
+ timer.unref?.();
370
+ const onData = (chunk) => {
371
+ bytesRead += chunk.length;
372
+ if (bytesRead > MAX_DRAIN_BYTES) {
373
+ forceClose();
374
+ }
375
+ };
376
+ incoming.on("data", onData);
377
+ incoming.on("end", cleanup);
378
+ incoming.on("error", cleanup);
379
+ incoming.resume();
380
+ };
335
381
  var handleRequestError = () => new Response(null, {
336
382
  status: 400
337
383
  });
@@ -358,15 +404,32 @@ var flushHeaders = (outgoing) => {
358
404
  };
359
405
  var responseViaCache = async (res, outgoing) => {
360
406
  let [status, body, header] = res[cacheKey];
361
- if (header instanceof Headers) {
407
+ let hasContentLength = false;
408
+ if (!header) {
409
+ header = { "content-type": "text/plain; charset=UTF-8" };
410
+ } else if (header instanceof Headers) {
411
+ hasContentLength = header.has("content-length");
362
412
  header = buildOutgoingHttpHeaders(header);
413
+ } else if (Array.isArray(header)) {
414
+ const headerObj = new Headers(header);
415
+ hasContentLength = headerObj.has("content-length");
416
+ header = buildOutgoingHttpHeaders(headerObj);
417
+ } else {
418
+ for (const key in header) {
419
+ if (key.length === 14 && key.toLowerCase() === "content-length") {
420
+ hasContentLength = true;
421
+ break;
422
+ }
423
+ }
363
424
  }
364
- if (typeof body === "string") {
365
- header["Content-Length"] = Buffer.byteLength(body);
366
- } else if (body instanceof Uint8Array) {
367
- header["Content-Length"] = body.byteLength;
368
- } else if (body instanceof Blob) {
369
- header["Content-Length"] = body.size;
425
+ if (!hasContentLength) {
426
+ if (typeof body === "string") {
427
+ header["Content-Length"] = Buffer.byteLength(body);
428
+ } else if (body instanceof Uint8Array) {
429
+ header["Content-Length"] = body.byteLength;
430
+ } else if (body instanceof Blob) {
431
+ header["Content-Length"] = body.size;
432
+ }
370
433
  }
371
434
  outgoing.writeHead(status, header);
372
435
  if (typeof body === "string" || body instanceof Uint8Array) {
@@ -486,14 +549,18 @@ var getRequestListener = (fetchCallback, options = {}) => {
486
549
  setTimeout(() => {
487
550
  if (!incomingEnded) {
488
551
  setTimeout(() => {
489
- incoming.destroy();
490
- outgoing.destroy();
552
+ drainIncoming(incoming);
491
553
  });
492
554
  }
493
555
  });
494
556
  }
495
557
  };
496
558
  }
559
+ outgoing.on("finish", () => {
560
+ if (!incomingEnded) {
561
+ drainIncoming(incoming);
562
+ }
563
+ });
497
564
  }
498
565
  outgoing.on("close", () => {
499
566
  const abortController = req[abortControllerKey];
@@ -508,7 +575,7 @@ var getRequestListener = (fetchCallback, options = {}) => {
508
575
  setTimeout(() => {
509
576
  if (!incomingEnded) {
510
577
  setTimeout(() => {
511
- incoming.destroy();
578
+ drainIncoming(incoming);
512
579
  });
513
580
  }
514
581
  });
@@ -5,7 +5,7 @@ declare const cacheKey: unique symbol;
5
5
  type InternalCache = [
6
6
  number,
7
7
  string | ReadableStream,
8
- Record<string, string> | Headers | OutgoingHttpHeaders
8
+ Record<string, string> | [string, string][] | Headers | OutgoingHttpHeaders | undefined
9
9
  ];
10
10
  declare const GlobalResponse: {
11
11
  new (body?: BodyInit | null, init?: ResponseInit): globalThis.Response;
@@ -5,7 +5,7 @@ declare const cacheKey: unique symbol;
5
5
  type InternalCache = [
6
6
  number,
7
7
  string | ReadableStream,
8
- Record<string, string> | Headers | OutgoingHttpHeaders
8
+ Record<string, string> | [string, string][] | Headers | OutgoingHttpHeaders | undefined
9
9
  ];
10
10
  declare const GlobalResponse: {
11
11
  new (body?: BodyInit | null, init?: ResponseInit): globalThis.Response;
package/dist/response.js CHANGED
@@ -53,15 +53,17 @@ var Response = class _Response {
53
53
  this.#init = init;
54
54
  }
55
55
  if (typeof body === "string" || typeof body?.getReader !== "undefined" || body instanceof Blob || body instanceof Uint8Array) {
56
- headers ||= init?.headers || { "content-type": "text/plain; charset=UTF-8" };
57
- this[cacheKey] = [init?.status || 200, body, headers];
56
+ ;
57
+ this[cacheKey] = [init?.status || 200, body, headers || init?.headers];
58
58
  }
59
59
  }
60
60
  get headers() {
61
61
  const cache = this[cacheKey];
62
62
  if (cache) {
63
63
  if (!(cache[2] instanceof Headers)) {
64
- cache[2] = new Headers(cache[2]);
64
+ cache[2] = new Headers(
65
+ cache[2] || { "content-type": "text/plain; charset=UTF-8" }
66
+ );
65
67
  }
66
68
  return cache[2];
67
69
  }
package/dist/response.mjs CHANGED
@@ -27,15 +27,17 @@ var Response = class _Response {
27
27
  this.#init = init;
28
28
  }
29
29
  if (typeof body === "string" || typeof body?.getReader !== "undefined" || body instanceof Blob || body instanceof Uint8Array) {
30
- headers ||= init?.headers || { "content-type": "text/plain; charset=UTF-8" };
31
- this[cacheKey] = [init?.status || 200, body, headers];
30
+ ;
31
+ this[cacheKey] = [init?.status || 200, body, headers || init?.headers];
32
32
  }
33
33
  }
34
34
  get headers() {
35
35
  const cache = this[cacheKey];
36
36
  if (cache) {
37
37
  if (!(cache[2] instanceof Headers)) {
38
- cache[2] = new Headers(cache[2]);
38
+ cache[2] = new Headers(
39
+ cache[2] || { "content-type": "text/plain; charset=UTF-8" }
40
+ );
39
41
  }
40
42
  return cache[2];
41
43
  }
package/dist/server.js CHANGED
@@ -254,15 +254,17 @@ var Response2 = class _Response {
254
254
  this.#init = init;
255
255
  }
256
256
  if (typeof body === "string" || typeof body?.getReader !== "undefined" || body instanceof Blob || body instanceof Uint8Array) {
257
- headers ||= init?.headers || { "content-type": "text/plain; charset=UTF-8" };
258
- this[cacheKey] = [init?.status || 200, body, headers];
257
+ ;
258
+ this[cacheKey] = [init?.status || 200, body, headers || init?.headers];
259
259
  }
260
260
  }
261
261
  get headers() {
262
262
  const cache = this[cacheKey];
263
263
  if (cache) {
264
264
  if (!(cache[2] instanceof Headers)) {
265
- cache[2] = new Headers(cache[2]);
265
+ cache[2] = new Headers(
266
+ cache[2] || { "content-type": "text/plain; charset=UTF-8" }
267
+ );
266
268
  }
267
269
  return cache[2];
268
270
  }
@@ -370,6 +372,50 @@ if (typeof global.crypto === "undefined") {
370
372
 
371
373
  // src/listener.ts
372
374
  var outgoingEnded = Symbol("outgoingEnded");
375
+ var incomingDraining = Symbol("incomingDraining");
376
+ var DRAIN_TIMEOUT_MS = 500;
377
+ var MAX_DRAIN_BYTES = 64 * 1024 * 1024;
378
+ var drainIncoming = (incoming) => {
379
+ const incomingWithDrainState = incoming;
380
+ if (incoming.destroyed || incomingWithDrainState[incomingDraining]) {
381
+ return;
382
+ }
383
+ incomingWithDrainState[incomingDraining] = true;
384
+ if (incoming instanceof import_node_http22.Http2ServerRequest) {
385
+ try {
386
+ ;
387
+ incoming.stream?.close?.(import_node_http22.constants.NGHTTP2_NO_ERROR);
388
+ } catch {
389
+ }
390
+ return;
391
+ }
392
+ let bytesRead = 0;
393
+ const cleanup = () => {
394
+ clearTimeout(timer);
395
+ incoming.off("data", onData);
396
+ incoming.off("end", cleanup);
397
+ incoming.off("error", cleanup);
398
+ };
399
+ const forceClose = () => {
400
+ cleanup();
401
+ const socket = incoming.socket;
402
+ if (socket && !socket.destroyed) {
403
+ socket.destroySoon();
404
+ }
405
+ };
406
+ const timer = setTimeout(forceClose, DRAIN_TIMEOUT_MS);
407
+ timer.unref?.();
408
+ const onData = (chunk) => {
409
+ bytesRead += chunk.length;
410
+ if (bytesRead > MAX_DRAIN_BYTES) {
411
+ forceClose();
412
+ }
413
+ };
414
+ incoming.on("data", onData);
415
+ incoming.on("end", cleanup);
416
+ incoming.on("error", cleanup);
417
+ incoming.resume();
418
+ };
373
419
  var handleRequestError = () => new Response(null, {
374
420
  status: 400
375
421
  });
@@ -396,15 +442,32 @@ var flushHeaders = (outgoing) => {
396
442
  };
397
443
  var responseViaCache = async (res, outgoing) => {
398
444
  let [status, body, header] = res[cacheKey];
399
- if (header instanceof Headers) {
445
+ let hasContentLength = false;
446
+ if (!header) {
447
+ header = { "content-type": "text/plain; charset=UTF-8" };
448
+ } else if (header instanceof Headers) {
449
+ hasContentLength = header.has("content-length");
400
450
  header = buildOutgoingHttpHeaders(header);
451
+ } else if (Array.isArray(header)) {
452
+ const headerObj = new Headers(header);
453
+ hasContentLength = headerObj.has("content-length");
454
+ header = buildOutgoingHttpHeaders(headerObj);
455
+ } else {
456
+ for (const key in header) {
457
+ if (key.length === 14 && key.toLowerCase() === "content-length") {
458
+ hasContentLength = true;
459
+ break;
460
+ }
461
+ }
401
462
  }
402
- if (typeof body === "string") {
403
- header["Content-Length"] = Buffer.byteLength(body);
404
- } else if (body instanceof Uint8Array) {
405
- header["Content-Length"] = body.byteLength;
406
- } else if (body instanceof Blob) {
407
- header["Content-Length"] = body.size;
463
+ if (!hasContentLength) {
464
+ if (typeof body === "string") {
465
+ header["Content-Length"] = Buffer.byteLength(body);
466
+ } else if (body instanceof Uint8Array) {
467
+ header["Content-Length"] = body.byteLength;
468
+ } else if (body instanceof Blob) {
469
+ header["Content-Length"] = body.size;
470
+ }
408
471
  }
409
472
  outgoing.writeHead(status, header);
410
473
  if (typeof body === "string" || body instanceof Uint8Array) {
@@ -524,14 +587,18 @@ var getRequestListener = (fetchCallback, options = {}) => {
524
587
  setTimeout(() => {
525
588
  if (!incomingEnded) {
526
589
  setTimeout(() => {
527
- incoming.destroy();
528
- outgoing.destroy();
590
+ drainIncoming(incoming);
529
591
  });
530
592
  }
531
593
  });
532
594
  }
533
595
  };
534
596
  }
597
+ outgoing.on("finish", () => {
598
+ if (!incomingEnded) {
599
+ drainIncoming(incoming);
600
+ }
601
+ });
535
602
  }
536
603
  outgoing.on("close", () => {
537
604
  const abortController = req[abortControllerKey];
@@ -546,7 +613,7 @@ var getRequestListener = (fetchCallback, options = {}) => {
546
613
  setTimeout(() => {
547
614
  if (!incomingEnded) {
548
615
  setTimeout(() => {
549
- incoming.destroy();
616
+ drainIncoming(incoming);
550
617
  });
551
618
  }
552
619
  });
package/dist/server.mjs CHANGED
@@ -2,7 +2,7 @@
2
2
  import { createServer as createServerHTTP } from "http";
3
3
 
4
4
  // src/listener.ts
5
- import { Http2ServerRequest as Http2ServerRequest2 } from "http2";
5
+ import { Http2ServerRequest as Http2ServerRequest2, constants as h2constants } from "http2";
6
6
 
7
7
  // src/request.ts
8
8
  import { Http2ServerRequest } from "http2";
@@ -219,15 +219,17 @@ var Response2 = class _Response {
219
219
  this.#init = init;
220
220
  }
221
221
  if (typeof body === "string" || typeof body?.getReader !== "undefined" || body instanceof Blob || body instanceof Uint8Array) {
222
- headers ||= init?.headers || { "content-type": "text/plain; charset=UTF-8" };
223
- this[cacheKey] = [init?.status || 200, body, headers];
222
+ ;
223
+ this[cacheKey] = [init?.status || 200, body, headers || init?.headers];
224
224
  }
225
225
  }
226
226
  get headers() {
227
227
  const cache = this[cacheKey];
228
228
  if (cache) {
229
229
  if (!(cache[2] instanceof Headers)) {
230
- cache[2] = new Headers(cache[2]);
230
+ cache[2] = new Headers(
231
+ cache[2] || { "content-type": "text/plain; charset=UTF-8" }
232
+ );
231
233
  }
232
234
  return cache[2];
233
235
  }
@@ -335,6 +337,50 @@ if (typeof global.crypto === "undefined") {
335
337
 
336
338
  // src/listener.ts
337
339
  var outgoingEnded = Symbol("outgoingEnded");
340
+ var incomingDraining = Symbol("incomingDraining");
341
+ var DRAIN_TIMEOUT_MS = 500;
342
+ var MAX_DRAIN_BYTES = 64 * 1024 * 1024;
343
+ var drainIncoming = (incoming) => {
344
+ const incomingWithDrainState = incoming;
345
+ if (incoming.destroyed || incomingWithDrainState[incomingDraining]) {
346
+ return;
347
+ }
348
+ incomingWithDrainState[incomingDraining] = true;
349
+ if (incoming instanceof Http2ServerRequest2) {
350
+ try {
351
+ ;
352
+ incoming.stream?.close?.(h2constants.NGHTTP2_NO_ERROR);
353
+ } catch {
354
+ }
355
+ return;
356
+ }
357
+ let bytesRead = 0;
358
+ const cleanup = () => {
359
+ clearTimeout(timer);
360
+ incoming.off("data", onData);
361
+ incoming.off("end", cleanup);
362
+ incoming.off("error", cleanup);
363
+ };
364
+ const forceClose = () => {
365
+ cleanup();
366
+ const socket = incoming.socket;
367
+ if (socket && !socket.destroyed) {
368
+ socket.destroySoon();
369
+ }
370
+ };
371
+ const timer = setTimeout(forceClose, DRAIN_TIMEOUT_MS);
372
+ timer.unref?.();
373
+ const onData = (chunk) => {
374
+ bytesRead += chunk.length;
375
+ if (bytesRead > MAX_DRAIN_BYTES) {
376
+ forceClose();
377
+ }
378
+ };
379
+ incoming.on("data", onData);
380
+ incoming.on("end", cleanup);
381
+ incoming.on("error", cleanup);
382
+ incoming.resume();
383
+ };
338
384
  var handleRequestError = () => new Response(null, {
339
385
  status: 400
340
386
  });
@@ -361,15 +407,32 @@ var flushHeaders = (outgoing) => {
361
407
  };
362
408
  var responseViaCache = async (res, outgoing) => {
363
409
  let [status, body, header] = res[cacheKey];
364
- if (header instanceof Headers) {
410
+ let hasContentLength = false;
411
+ if (!header) {
412
+ header = { "content-type": "text/plain; charset=UTF-8" };
413
+ } else if (header instanceof Headers) {
414
+ hasContentLength = header.has("content-length");
365
415
  header = buildOutgoingHttpHeaders(header);
416
+ } else if (Array.isArray(header)) {
417
+ const headerObj = new Headers(header);
418
+ hasContentLength = headerObj.has("content-length");
419
+ header = buildOutgoingHttpHeaders(headerObj);
420
+ } else {
421
+ for (const key in header) {
422
+ if (key.length === 14 && key.toLowerCase() === "content-length") {
423
+ hasContentLength = true;
424
+ break;
425
+ }
426
+ }
366
427
  }
367
- if (typeof body === "string") {
368
- header["Content-Length"] = Buffer.byteLength(body);
369
- } else if (body instanceof Uint8Array) {
370
- header["Content-Length"] = body.byteLength;
371
- } else if (body instanceof Blob) {
372
- header["Content-Length"] = body.size;
428
+ if (!hasContentLength) {
429
+ if (typeof body === "string") {
430
+ header["Content-Length"] = Buffer.byteLength(body);
431
+ } else if (body instanceof Uint8Array) {
432
+ header["Content-Length"] = body.byteLength;
433
+ } else if (body instanceof Blob) {
434
+ header["Content-Length"] = body.size;
435
+ }
373
436
  }
374
437
  outgoing.writeHead(status, header);
375
438
  if (typeof body === "string" || body instanceof Uint8Array) {
@@ -489,14 +552,18 @@ var getRequestListener = (fetchCallback, options = {}) => {
489
552
  setTimeout(() => {
490
553
  if (!incomingEnded) {
491
554
  setTimeout(() => {
492
- incoming.destroy();
493
- outgoing.destroy();
555
+ drainIncoming(incoming);
494
556
  });
495
557
  }
496
558
  });
497
559
  }
498
560
  };
499
561
  }
562
+ outgoing.on("finish", () => {
563
+ if (!incomingEnded) {
564
+ drainIncoming(incoming);
565
+ }
566
+ });
500
567
  }
501
568
  outgoing.on("close", () => {
502
569
  const abortController = req[abortControllerKey];
@@ -511,7 +578,7 @@ var getRequestListener = (fetchCallback, options = {}) => {
511
578
  setTimeout(() => {
512
579
  if (!incomingEnded) {
513
580
  setTimeout(() => {
514
- incoming.destroy();
581
+ drainIncoming(incoming);
515
582
  });
516
583
  }
517
584
  });
package/dist/vercel.js CHANGED
@@ -252,15 +252,17 @@ var Response2 = class _Response {
252
252
  this.#init = init;
253
253
  }
254
254
  if (typeof body === "string" || typeof body?.getReader !== "undefined" || body instanceof Blob || body instanceof Uint8Array) {
255
- headers ||= init?.headers || { "content-type": "text/plain; charset=UTF-8" };
256
- this[cacheKey] = [init?.status || 200, body, headers];
255
+ ;
256
+ this[cacheKey] = [init?.status || 200, body, headers || init?.headers];
257
257
  }
258
258
  }
259
259
  get headers() {
260
260
  const cache = this[cacheKey];
261
261
  if (cache) {
262
262
  if (!(cache[2] instanceof Headers)) {
263
- cache[2] = new Headers(cache[2]);
263
+ cache[2] = new Headers(
264
+ cache[2] || { "content-type": "text/plain; charset=UTF-8" }
265
+ );
264
266
  }
265
267
  return cache[2];
266
268
  }
@@ -368,6 +370,50 @@ if (typeof global.crypto === "undefined") {
368
370
 
369
371
  // src/listener.ts
370
372
  var outgoingEnded = Symbol("outgoingEnded");
373
+ var incomingDraining = Symbol("incomingDraining");
374
+ var DRAIN_TIMEOUT_MS = 500;
375
+ var MAX_DRAIN_BYTES = 64 * 1024 * 1024;
376
+ var drainIncoming = (incoming) => {
377
+ const incomingWithDrainState = incoming;
378
+ if (incoming.destroyed || incomingWithDrainState[incomingDraining]) {
379
+ return;
380
+ }
381
+ incomingWithDrainState[incomingDraining] = true;
382
+ if (incoming instanceof import_node_http22.Http2ServerRequest) {
383
+ try {
384
+ ;
385
+ incoming.stream?.close?.(import_node_http22.constants.NGHTTP2_NO_ERROR);
386
+ } catch {
387
+ }
388
+ return;
389
+ }
390
+ let bytesRead = 0;
391
+ const cleanup = () => {
392
+ clearTimeout(timer);
393
+ incoming.off("data", onData);
394
+ incoming.off("end", cleanup);
395
+ incoming.off("error", cleanup);
396
+ };
397
+ const forceClose = () => {
398
+ cleanup();
399
+ const socket = incoming.socket;
400
+ if (socket && !socket.destroyed) {
401
+ socket.destroySoon();
402
+ }
403
+ };
404
+ const timer = setTimeout(forceClose, DRAIN_TIMEOUT_MS);
405
+ timer.unref?.();
406
+ const onData = (chunk) => {
407
+ bytesRead += chunk.length;
408
+ if (bytesRead > MAX_DRAIN_BYTES) {
409
+ forceClose();
410
+ }
411
+ };
412
+ incoming.on("data", onData);
413
+ incoming.on("end", cleanup);
414
+ incoming.on("error", cleanup);
415
+ incoming.resume();
416
+ };
371
417
  var handleRequestError = () => new Response(null, {
372
418
  status: 400
373
419
  });
@@ -394,15 +440,32 @@ var flushHeaders = (outgoing) => {
394
440
  };
395
441
  var responseViaCache = async (res, outgoing) => {
396
442
  let [status, body, header] = res[cacheKey];
397
- if (header instanceof Headers) {
443
+ let hasContentLength = false;
444
+ if (!header) {
445
+ header = { "content-type": "text/plain; charset=UTF-8" };
446
+ } else if (header instanceof Headers) {
447
+ hasContentLength = header.has("content-length");
398
448
  header = buildOutgoingHttpHeaders(header);
449
+ } else if (Array.isArray(header)) {
450
+ const headerObj = new Headers(header);
451
+ hasContentLength = headerObj.has("content-length");
452
+ header = buildOutgoingHttpHeaders(headerObj);
453
+ } else {
454
+ for (const key in header) {
455
+ if (key.length === 14 && key.toLowerCase() === "content-length") {
456
+ hasContentLength = true;
457
+ break;
458
+ }
459
+ }
399
460
  }
400
- if (typeof body === "string") {
401
- header["Content-Length"] = Buffer.byteLength(body);
402
- } else if (body instanceof Uint8Array) {
403
- header["Content-Length"] = body.byteLength;
404
- } else if (body instanceof Blob) {
405
- header["Content-Length"] = body.size;
461
+ if (!hasContentLength) {
462
+ if (typeof body === "string") {
463
+ header["Content-Length"] = Buffer.byteLength(body);
464
+ } else if (body instanceof Uint8Array) {
465
+ header["Content-Length"] = body.byteLength;
466
+ } else if (body instanceof Blob) {
467
+ header["Content-Length"] = body.size;
468
+ }
406
469
  }
407
470
  outgoing.writeHead(status, header);
408
471
  if (typeof body === "string" || body instanceof Uint8Array) {
@@ -522,14 +585,18 @@ var getRequestListener = (fetchCallback, options = {}) => {
522
585
  setTimeout(() => {
523
586
  if (!incomingEnded) {
524
587
  setTimeout(() => {
525
- incoming.destroy();
526
- outgoing.destroy();
588
+ drainIncoming(incoming);
527
589
  });
528
590
  }
529
591
  });
530
592
  }
531
593
  };
532
594
  }
595
+ outgoing.on("finish", () => {
596
+ if (!incomingEnded) {
597
+ drainIncoming(incoming);
598
+ }
599
+ });
533
600
  }
534
601
  outgoing.on("close", () => {
535
602
  const abortController = req[abortControllerKey];
@@ -544,7 +611,7 @@ var getRequestListener = (fetchCallback, options = {}) => {
544
611
  setTimeout(() => {
545
612
  if (!incomingEnded) {
546
613
  setTimeout(() => {
547
- incoming.destroy();
614
+ drainIncoming(incoming);
548
615
  });
549
616
  }
550
617
  });
package/dist/vercel.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/listener.ts
2
- import { Http2ServerRequest as Http2ServerRequest2 } from "http2";
2
+ import { Http2ServerRequest as Http2ServerRequest2, constants as h2constants } from "http2";
3
3
 
4
4
  // src/request.ts
5
5
  import { Http2ServerRequest } from "http2";
@@ -216,15 +216,17 @@ var Response2 = class _Response {
216
216
  this.#init = init;
217
217
  }
218
218
  if (typeof body === "string" || typeof body?.getReader !== "undefined" || body instanceof Blob || body instanceof Uint8Array) {
219
- headers ||= init?.headers || { "content-type": "text/plain; charset=UTF-8" };
220
- this[cacheKey] = [init?.status || 200, body, headers];
219
+ ;
220
+ this[cacheKey] = [init?.status || 200, body, headers || init?.headers];
221
221
  }
222
222
  }
223
223
  get headers() {
224
224
  const cache = this[cacheKey];
225
225
  if (cache) {
226
226
  if (!(cache[2] instanceof Headers)) {
227
- cache[2] = new Headers(cache[2]);
227
+ cache[2] = new Headers(
228
+ cache[2] || { "content-type": "text/plain; charset=UTF-8" }
229
+ );
228
230
  }
229
231
  return cache[2];
230
232
  }
@@ -332,6 +334,50 @@ if (typeof global.crypto === "undefined") {
332
334
 
333
335
  // src/listener.ts
334
336
  var outgoingEnded = Symbol("outgoingEnded");
337
+ var incomingDraining = Symbol("incomingDraining");
338
+ var DRAIN_TIMEOUT_MS = 500;
339
+ var MAX_DRAIN_BYTES = 64 * 1024 * 1024;
340
+ var drainIncoming = (incoming) => {
341
+ const incomingWithDrainState = incoming;
342
+ if (incoming.destroyed || incomingWithDrainState[incomingDraining]) {
343
+ return;
344
+ }
345
+ incomingWithDrainState[incomingDraining] = true;
346
+ if (incoming instanceof Http2ServerRequest2) {
347
+ try {
348
+ ;
349
+ incoming.stream?.close?.(h2constants.NGHTTP2_NO_ERROR);
350
+ } catch {
351
+ }
352
+ return;
353
+ }
354
+ let bytesRead = 0;
355
+ const cleanup = () => {
356
+ clearTimeout(timer);
357
+ incoming.off("data", onData);
358
+ incoming.off("end", cleanup);
359
+ incoming.off("error", cleanup);
360
+ };
361
+ const forceClose = () => {
362
+ cleanup();
363
+ const socket = incoming.socket;
364
+ if (socket && !socket.destroyed) {
365
+ socket.destroySoon();
366
+ }
367
+ };
368
+ const timer = setTimeout(forceClose, DRAIN_TIMEOUT_MS);
369
+ timer.unref?.();
370
+ const onData = (chunk) => {
371
+ bytesRead += chunk.length;
372
+ if (bytesRead > MAX_DRAIN_BYTES) {
373
+ forceClose();
374
+ }
375
+ };
376
+ incoming.on("data", onData);
377
+ incoming.on("end", cleanup);
378
+ incoming.on("error", cleanup);
379
+ incoming.resume();
380
+ };
335
381
  var handleRequestError = () => new Response(null, {
336
382
  status: 400
337
383
  });
@@ -358,15 +404,32 @@ var flushHeaders = (outgoing) => {
358
404
  };
359
405
  var responseViaCache = async (res, outgoing) => {
360
406
  let [status, body, header] = res[cacheKey];
361
- if (header instanceof Headers) {
407
+ let hasContentLength = false;
408
+ if (!header) {
409
+ header = { "content-type": "text/plain; charset=UTF-8" };
410
+ } else if (header instanceof Headers) {
411
+ hasContentLength = header.has("content-length");
362
412
  header = buildOutgoingHttpHeaders(header);
413
+ } else if (Array.isArray(header)) {
414
+ const headerObj = new Headers(header);
415
+ hasContentLength = headerObj.has("content-length");
416
+ header = buildOutgoingHttpHeaders(headerObj);
417
+ } else {
418
+ for (const key in header) {
419
+ if (key.length === 14 && key.toLowerCase() === "content-length") {
420
+ hasContentLength = true;
421
+ break;
422
+ }
423
+ }
363
424
  }
364
- if (typeof body === "string") {
365
- header["Content-Length"] = Buffer.byteLength(body);
366
- } else if (body instanceof Uint8Array) {
367
- header["Content-Length"] = body.byteLength;
368
- } else if (body instanceof Blob) {
369
- header["Content-Length"] = body.size;
425
+ if (!hasContentLength) {
426
+ if (typeof body === "string") {
427
+ header["Content-Length"] = Buffer.byteLength(body);
428
+ } else if (body instanceof Uint8Array) {
429
+ header["Content-Length"] = body.byteLength;
430
+ } else if (body instanceof Blob) {
431
+ header["Content-Length"] = body.size;
432
+ }
370
433
  }
371
434
  outgoing.writeHead(status, header);
372
435
  if (typeof body === "string" || body instanceof Uint8Array) {
@@ -486,14 +549,18 @@ var getRequestListener = (fetchCallback, options = {}) => {
486
549
  setTimeout(() => {
487
550
  if (!incomingEnded) {
488
551
  setTimeout(() => {
489
- incoming.destroy();
490
- outgoing.destroy();
552
+ drainIncoming(incoming);
491
553
  });
492
554
  }
493
555
  });
494
556
  }
495
557
  };
496
558
  }
559
+ outgoing.on("finish", () => {
560
+ if (!incomingEnded) {
561
+ drainIncoming(incoming);
562
+ }
563
+ });
497
564
  }
498
565
  outgoing.on("close", () => {
499
566
  const abortController = req[abortControllerKey];
@@ -508,7 +575,7 @@ var getRequestListener = (fetchCallback, options = {}) => {
508
575
  setTimeout(() => {
509
576
  if (!incomingEnded) {
510
577
  setTimeout(() => {
511
- incoming.destroy();
578
+ drainIncoming(incoming);
512
579
  });
513
580
  }
514
581
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hono/node-server",
3
- "version": "1.19.10",
3
+ "version": "1.19.12",
4
4
  "description": "Node.js Adapter for Hono",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",