@hono/node-server 1.19.10 → 1.19.11

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.
@@ -1,2 +1,2 @@
1
1
 
2
- export { }
2
+ export { }
package/dist/globals.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
 
2
- export { }
2
+ export { }
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
  }
@@ -400,15 +402,32 @@ var flushHeaders = (outgoing) => {
400
402
  };
401
403
  var responseViaCache = async (res, outgoing) => {
402
404
  let [status, body, header] = res[cacheKey];
403
- if (header instanceof Headers) {
405
+ let hasContentLength = false;
406
+ if (!header) {
407
+ header = { "content-type": "text/plain; charset=UTF-8" };
408
+ } else if (header instanceof Headers) {
409
+ hasContentLength = header.has("content-length");
404
410
  header = buildOutgoingHttpHeaders(header);
411
+ } else if (Array.isArray(header)) {
412
+ const headerObj = new Headers(header);
413
+ hasContentLength = headerObj.has("content-length");
414
+ header = buildOutgoingHttpHeaders(headerObj);
415
+ } else {
416
+ for (const key in header) {
417
+ if (key.length === 14 && key.toLowerCase() === "content-length") {
418
+ hasContentLength = true;
419
+ break;
420
+ }
421
+ }
405
422
  }
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;
423
+ if (!hasContentLength) {
424
+ if (typeof body === "string") {
425
+ header["Content-Length"] = Buffer.byteLength(body);
426
+ } else if (body instanceof Uint8Array) {
427
+ header["Content-Length"] = body.byteLength;
428
+ } else if (body instanceof Blob) {
429
+ header["Content-Length"] = body.size;
430
+ }
412
431
  }
413
432
  outgoing.writeHead(status, header);
414
433
  if (typeof body === "string" || body instanceof Uint8Array) {
package/dist/index.mjs CHANGED
@@ -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
  }
@@ -361,15 +363,32 @@ var flushHeaders = (outgoing) => {
361
363
  };
362
364
  var responseViaCache = async (res, outgoing) => {
363
365
  let [status, body, header] = res[cacheKey];
364
- if (header instanceof Headers) {
366
+ let hasContentLength = false;
367
+ if (!header) {
368
+ header = { "content-type": "text/plain; charset=UTF-8" };
369
+ } else if (header instanceof Headers) {
370
+ hasContentLength = header.has("content-length");
365
371
  header = buildOutgoingHttpHeaders(header);
372
+ } else if (Array.isArray(header)) {
373
+ const headerObj = new Headers(header);
374
+ hasContentLength = headerObj.has("content-length");
375
+ header = buildOutgoingHttpHeaders(headerObj);
376
+ } else {
377
+ for (const key in header) {
378
+ if (key.length === 14 && key.toLowerCase() === "content-length") {
379
+ hasContentLength = true;
380
+ break;
381
+ }
382
+ }
366
383
  }
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;
384
+ if (!hasContentLength) {
385
+ if (typeof body === "string") {
386
+ header["Content-Length"] = Buffer.byteLength(body);
387
+ } else if (body instanceof Uint8Array) {
388
+ header["Content-Length"] = body.byteLength;
389
+ } else if (body instanceof Blob) {
390
+ header["Content-Length"] = body.size;
391
+ }
373
392
  }
374
393
  outgoing.writeHead(status, header);
375
394
  if (typeof body === "string" || body instanceof Uint8Array) {
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
  }
@@ -392,15 +394,32 @@ var flushHeaders = (outgoing) => {
392
394
  };
393
395
  var responseViaCache = async (res, outgoing) => {
394
396
  let [status, body, header] = res[cacheKey];
395
- if (header instanceof Headers) {
397
+ let hasContentLength = false;
398
+ if (!header) {
399
+ header = { "content-type": "text/plain; charset=UTF-8" };
400
+ } else if (header instanceof Headers) {
401
+ hasContentLength = header.has("content-length");
396
402
  header = buildOutgoingHttpHeaders(header);
403
+ } else if (Array.isArray(header)) {
404
+ const headerObj = new Headers(header);
405
+ hasContentLength = headerObj.has("content-length");
406
+ header = buildOutgoingHttpHeaders(headerObj);
407
+ } else {
408
+ for (const key in header) {
409
+ if (key.length === 14 && key.toLowerCase() === "content-length") {
410
+ hasContentLength = true;
411
+ break;
412
+ }
413
+ }
397
414
  }
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;
415
+ if (!hasContentLength) {
416
+ if (typeof body === "string") {
417
+ header["Content-Length"] = Buffer.byteLength(body);
418
+ } else if (body instanceof Uint8Array) {
419
+ header["Content-Length"] = body.byteLength;
420
+ } else if (body instanceof Blob) {
421
+ header["Content-Length"] = body.size;
422
+ }
404
423
  }
405
424
  outgoing.writeHead(status, header);
406
425
  if (typeof body === "string" || body instanceof Uint8Array) {
package/dist/listener.mjs CHANGED
@@ -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
  }
@@ -358,15 +360,32 @@ var flushHeaders = (outgoing) => {
358
360
  };
359
361
  var responseViaCache = async (res, outgoing) => {
360
362
  let [status, body, header] = res[cacheKey];
361
- if (header instanceof Headers) {
363
+ let hasContentLength = false;
364
+ if (!header) {
365
+ header = { "content-type": "text/plain; charset=UTF-8" };
366
+ } else if (header instanceof Headers) {
367
+ hasContentLength = header.has("content-length");
362
368
  header = buildOutgoingHttpHeaders(header);
369
+ } else if (Array.isArray(header)) {
370
+ const headerObj = new Headers(header);
371
+ hasContentLength = headerObj.has("content-length");
372
+ header = buildOutgoingHttpHeaders(headerObj);
373
+ } else {
374
+ for (const key in header) {
375
+ if (key.length === 14 && key.toLowerCase() === "content-length") {
376
+ hasContentLength = true;
377
+ break;
378
+ }
379
+ }
363
380
  }
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;
381
+ if (!hasContentLength) {
382
+ if (typeof body === "string") {
383
+ header["Content-Length"] = Buffer.byteLength(body);
384
+ } else if (body instanceof Uint8Array) {
385
+ header["Content-Length"] = body.byteLength;
386
+ } else if (body instanceof Blob) {
387
+ header["Content-Length"] = body.size;
388
+ }
370
389
  }
371
390
  outgoing.writeHead(status, header);
372
391
  if (typeof body === "string" || body instanceof Uint8Array) {
@@ -22,4 +22,4 @@ declare const abortControllerKey: unique symbol;
22
22
  declare const getAbortController: unique symbol;
23
23
  declare const newRequest: (incoming: IncomingMessage | Http2ServerRequest, defaultHostname?: string) => any;
24
24
 
25
- export { GlobalRequest, type IncomingMessageWithWrapBodyStream, Request, RequestError, abortControllerKey, getAbortController, newRequest, toRequestError, wrapBodyStream };
25
+ export { GlobalRequest, IncomingMessageWithWrapBodyStream, Request, RequestError, abortControllerKey, getAbortController, newRequest, toRequestError, wrapBodyStream };
package/dist/request.d.ts CHANGED
@@ -22,4 +22,4 @@ declare const abortControllerKey: unique symbol;
22
22
  declare const getAbortController: unique symbol;
23
23
  declare const newRequest: (incoming: IncomingMessage | Http2ServerRequest, defaultHostname?: string) => any;
24
24
 
25
- export { GlobalRequest, type IncomingMessageWithWrapBodyStream, Request, RequestError, abortControllerKey, getAbortController, newRequest, toRequestError, wrapBodyStream };
25
+ export { GlobalRequest, IncomingMessageWithWrapBodyStream, Request, RequestError, abortControllerKey, getAbortController, newRequest, toRequestError, wrapBodyStream };
@@ -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;
@@ -23,4 +23,4 @@ declare class Response {
23
23
  get ok(): boolean;
24
24
  }
25
25
 
26
- export { GlobalResponse, type InternalCache, Response, cacheKey };
26
+ export { GlobalResponse, InternalCache, Response, cacheKey };
@@ -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;
@@ -23,4 +23,4 @@ declare class Response {
23
23
  get ok(): boolean;
24
24
  }
25
25
 
26
- export { GlobalResponse, type InternalCache, Response, cacheKey };
26
+ export { GlobalResponse, InternalCache, Response, cacheKey };
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
  }
@@ -14,4 +14,4 @@ type ServeStaticOptions<E extends Env = Env> = {
14
14
  };
15
15
  declare const serveStatic: <E extends Env = any>(options?: ServeStaticOptions<E>) => MiddlewareHandler<E>;
16
16
 
17
- export { type ServeStaticOptions, serveStatic };
17
+ export { ServeStaticOptions, serveStatic };
@@ -14,4 +14,4 @@ type ServeStaticOptions<E extends Env = Env> = {
14
14
  };
15
15
  declare const serveStatic: <E extends Env = any>(options?: ServeStaticOptions<E>) => MiddlewareHandler<E>;
16
16
 
17
- export { type ServeStaticOptions, serveStatic };
17
+ export { ServeStaticOptions, serveStatic };
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
  }
@@ -396,15 +398,32 @@ var flushHeaders = (outgoing) => {
396
398
  };
397
399
  var responseViaCache = async (res, outgoing) => {
398
400
  let [status, body, header] = res[cacheKey];
399
- if (header instanceof Headers) {
401
+ let hasContentLength = false;
402
+ if (!header) {
403
+ header = { "content-type": "text/plain; charset=UTF-8" };
404
+ } else if (header instanceof Headers) {
405
+ hasContentLength = header.has("content-length");
400
406
  header = buildOutgoingHttpHeaders(header);
407
+ } else if (Array.isArray(header)) {
408
+ const headerObj = new Headers(header);
409
+ hasContentLength = headerObj.has("content-length");
410
+ header = buildOutgoingHttpHeaders(headerObj);
411
+ } else {
412
+ for (const key in header) {
413
+ if (key.length === 14 && key.toLowerCase() === "content-length") {
414
+ hasContentLength = true;
415
+ break;
416
+ }
417
+ }
401
418
  }
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;
419
+ if (!hasContentLength) {
420
+ if (typeof body === "string") {
421
+ header["Content-Length"] = Buffer.byteLength(body);
422
+ } else if (body instanceof Uint8Array) {
423
+ header["Content-Length"] = body.byteLength;
424
+ } else if (body instanceof Blob) {
425
+ header["Content-Length"] = body.size;
426
+ }
408
427
  }
409
428
  outgoing.writeHead(status, header);
410
429
  if (typeof body === "string" || body instanceof Uint8Array) {
package/dist/server.mjs CHANGED
@@ -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
  }
@@ -361,15 +363,32 @@ var flushHeaders = (outgoing) => {
361
363
  };
362
364
  var responseViaCache = async (res, outgoing) => {
363
365
  let [status, body, header] = res[cacheKey];
364
- if (header instanceof Headers) {
366
+ let hasContentLength = false;
367
+ if (!header) {
368
+ header = { "content-type": "text/plain; charset=UTF-8" };
369
+ } else if (header instanceof Headers) {
370
+ hasContentLength = header.has("content-length");
365
371
  header = buildOutgoingHttpHeaders(header);
372
+ } else if (Array.isArray(header)) {
373
+ const headerObj = new Headers(header);
374
+ hasContentLength = headerObj.has("content-length");
375
+ header = buildOutgoingHttpHeaders(headerObj);
376
+ } else {
377
+ for (const key in header) {
378
+ if (key.length === 14 && key.toLowerCase() === "content-length") {
379
+ hasContentLength = true;
380
+ break;
381
+ }
382
+ }
366
383
  }
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;
384
+ if (!hasContentLength) {
385
+ if (typeof body === "string") {
386
+ header["Content-Length"] = Buffer.byteLength(body);
387
+ } else if (body instanceof Uint8Array) {
388
+ header["Content-Length"] = body.byteLength;
389
+ } else if (body instanceof Blob) {
390
+ header["Content-Length"] = body.size;
391
+ }
373
392
  }
374
393
  outgoing.writeHead(status, header);
375
394
  if (typeof body === "string" || body instanceof Uint8Array) {
package/dist/types.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { IncomingMessage, ServerResponse, ServerOptions as ServerOptions$1, createServer, Server } from 'node:http';
2
- import { Http2ServerRequest, Http2ServerResponse, ServerOptions as ServerOptions$3, createServer as createServer$2, SecureServerOptions, createSecureServer, Http2Server, Http2SecureServer } from 'node:http2';
1
+ import { IncomingMessage, ServerResponse, Server, ServerOptions as ServerOptions$1, createServer } from 'node:http';
2
+ import { Http2ServerRequest, Http2ServerResponse, Http2Server, Http2SecureServer, ServerOptions as ServerOptions$3, createServer as createServer$2, SecureServerOptions, createSecureServer } from 'node:http2';
3
3
  import { ServerOptions as ServerOptions$2, createServer as createServer$1 } from 'node:https';
4
4
 
5
5
  type HttpBindings = {
@@ -41,4 +41,4 @@ type Options = {
41
41
  } & ServerOptions;
42
42
  type CustomErrorHandler = (err: unknown) => void | Response | Promise<void | Response>;
43
43
 
44
- export type { CustomErrorHandler, FetchCallback, Http2Bindings, HttpBindings, NextHandlerOption, Options, ServerOptions, ServerType };
44
+ export { CustomErrorHandler, FetchCallback, Http2Bindings, HttpBindings, NextHandlerOption, Options, ServerOptions, ServerType };
package/dist/types.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { IncomingMessage, ServerResponse, ServerOptions as ServerOptions$1, createServer, Server } from 'node:http';
2
- import { Http2ServerRequest, Http2ServerResponse, ServerOptions as ServerOptions$3, createServer as createServer$2, SecureServerOptions, createSecureServer, Http2Server, Http2SecureServer } from 'node:http2';
1
+ import { IncomingMessage, ServerResponse, Server, ServerOptions as ServerOptions$1, createServer } from 'node:http';
2
+ import { Http2ServerRequest, Http2ServerResponse, Http2Server, Http2SecureServer, ServerOptions as ServerOptions$3, createServer as createServer$2, SecureServerOptions, createSecureServer } from 'node:http2';
3
3
  import { ServerOptions as ServerOptions$2, createServer as createServer$1 } from 'node:https';
4
4
 
5
5
  type HttpBindings = {
@@ -41,4 +41,4 @@ type Options = {
41
41
  } & ServerOptions;
42
42
  type CustomErrorHandler = (err: unknown) => void | Response | Promise<void | Response>;
43
43
 
44
- export type { CustomErrorHandler, FetchCallback, Http2Bindings, HttpBindings, NextHandlerOption, Options, ServerOptions, ServerType };
44
+ export { CustomErrorHandler, FetchCallback, Http2Bindings, HttpBindings, NextHandlerOption, Options, ServerOptions, ServerType };
package/dist/utils.d.mts CHANGED
@@ -2,8 +2,8 @@ import { OutgoingHttpHeaders } from 'node:http';
2
2
  import { Writable } from 'node:stream';
3
3
 
4
4
  declare function readWithoutBlocking(readPromise: Promise<ReadableStreamReadResult<Uint8Array>>): Promise<ReadableStreamReadResult<Uint8Array> | undefined>;
5
- declare function writeFromReadableStreamDefaultReader(reader: ReadableStreamDefaultReader<Uint8Array>, writable: Writable, currentReadPromise?: Promise<ReadableStreamReadResult<Uint8Array>> | undefined): Promise<undefined>;
6
- declare function writeFromReadableStream(stream: ReadableStream<Uint8Array>, writable: Writable): Promise<undefined> | undefined;
5
+ declare function writeFromReadableStreamDefaultReader(reader: ReadableStreamDefaultReader<Uint8Array>, writable: Writable, currentReadPromise?: Promise<ReadableStreamReadResult<Uint8Array>> | undefined): Promise<void>;
6
+ declare function writeFromReadableStream(stream: ReadableStream<Uint8Array>, writable: Writable): Promise<void> | undefined;
7
7
  declare const buildOutgoingHttpHeaders: (headers: Headers | HeadersInit | null | undefined) => OutgoingHttpHeaders;
8
8
 
9
9
  export { buildOutgoingHttpHeaders, readWithoutBlocking, writeFromReadableStream, writeFromReadableStreamDefaultReader };
package/dist/utils.d.ts CHANGED
@@ -2,8 +2,8 @@ import { OutgoingHttpHeaders } from 'node:http';
2
2
  import { Writable } from 'node:stream';
3
3
 
4
4
  declare function readWithoutBlocking(readPromise: Promise<ReadableStreamReadResult<Uint8Array>>): Promise<ReadableStreamReadResult<Uint8Array> | undefined>;
5
- declare function writeFromReadableStreamDefaultReader(reader: ReadableStreamDefaultReader<Uint8Array>, writable: Writable, currentReadPromise?: Promise<ReadableStreamReadResult<Uint8Array>> | undefined): Promise<undefined>;
6
- declare function writeFromReadableStream(stream: ReadableStream<Uint8Array>, writable: Writable): Promise<undefined> | undefined;
5
+ declare function writeFromReadableStreamDefaultReader(reader: ReadableStreamDefaultReader<Uint8Array>, writable: Writable, currentReadPromise?: Promise<ReadableStreamReadResult<Uint8Array>> | undefined): Promise<void>;
6
+ declare function writeFromReadableStream(stream: ReadableStream<Uint8Array>, writable: Writable): Promise<void> | undefined;
7
7
  declare const buildOutgoingHttpHeaders: (headers: Headers | HeadersInit | null | undefined) => OutgoingHttpHeaders;
8
8
 
9
9
  export { buildOutgoingHttpHeaders, readWithoutBlocking, writeFromReadableStream, writeFromReadableStreamDefaultReader };
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
  }
@@ -394,15 +396,32 @@ var flushHeaders = (outgoing) => {
394
396
  };
395
397
  var responseViaCache = async (res, outgoing) => {
396
398
  let [status, body, header] = res[cacheKey];
397
- if (header instanceof Headers) {
399
+ let hasContentLength = false;
400
+ if (!header) {
401
+ header = { "content-type": "text/plain; charset=UTF-8" };
402
+ } else if (header instanceof Headers) {
403
+ hasContentLength = header.has("content-length");
398
404
  header = buildOutgoingHttpHeaders(header);
405
+ } else if (Array.isArray(header)) {
406
+ const headerObj = new Headers(header);
407
+ hasContentLength = headerObj.has("content-length");
408
+ header = buildOutgoingHttpHeaders(headerObj);
409
+ } else {
410
+ for (const key in header) {
411
+ if (key.length === 14 && key.toLowerCase() === "content-length") {
412
+ hasContentLength = true;
413
+ break;
414
+ }
415
+ }
399
416
  }
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;
417
+ if (!hasContentLength) {
418
+ if (typeof body === "string") {
419
+ header["Content-Length"] = Buffer.byteLength(body);
420
+ } else if (body instanceof Uint8Array) {
421
+ header["Content-Length"] = body.byteLength;
422
+ } else if (body instanceof Blob) {
423
+ header["Content-Length"] = body.size;
424
+ }
406
425
  }
407
426
  outgoing.writeHead(status, header);
408
427
  if (typeof body === "string" || body instanceof Uint8Array) {
package/dist/vercel.mjs CHANGED
@@ -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
  }
@@ -358,15 +360,32 @@ var flushHeaders = (outgoing) => {
358
360
  };
359
361
  var responseViaCache = async (res, outgoing) => {
360
362
  let [status, body, header] = res[cacheKey];
361
- if (header instanceof Headers) {
363
+ let hasContentLength = false;
364
+ if (!header) {
365
+ header = { "content-type": "text/plain; charset=UTF-8" };
366
+ } else if (header instanceof Headers) {
367
+ hasContentLength = header.has("content-length");
362
368
  header = buildOutgoingHttpHeaders(header);
369
+ } else if (Array.isArray(header)) {
370
+ const headerObj = new Headers(header);
371
+ hasContentLength = headerObj.has("content-length");
372
+ header = buildOutgoingHttpHeaders(headerObj);
373
+ } else {
374
+ for (const key in header) {
375
+ if (key.length === 14 && key.toLowerCase() === "content-length") {
376
+ hasContentLength = true;
377
+ break;
378
+ }
379
+ }
363
380
  }
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;
381
+ if (!hasContentLength) {
382
+ if (typeof body === "string") {
383
+ header["Content-Length"] = Buffer.byteLength(body);
384
+ } else if (body instanceof Uint8Array) {
385
+ header["Content-Length"] = body.byteLength;
386
+ } else if (body instanceof Blob) {
387
+ header["Content-Length"] = body.size;
388
+ }
370
389
  }
371
390
  outgoing.writeHead(status, header);
372
391
  if (typeof body === "string" || body instanceof Uint8Array) {
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.11",
4
4
  "description": "Node.js Adapter for Hono",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",