@hono/node-server 1.4.1 → 1.6.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/dist/server.mjs CHANGED
@@ -2,13 +2,33 @@
2
2
  import { createServer as createServerHTTP } from "http";
3
3
 
4
4
  // src/request.ts
5
- import { resolve } from "path";
5
+ import { Http2ServerRequest } from "http2";
6
6
  import { Readable } from "stream";
7
+ var GlobalRequest = global.Request;
8
+ var Request = class extends GlobalRequest {
9
+ constructor(input, options) {
10
+ if (typeof input === "object" && getRequestCache in input) {
11
+ input = input[getRequestCache]();
12
+ }
13
+ if (options?.body instanceof ReadableStream) {
14
+ ;
15
+ options.duplex = "half";
16
+ }
17
+ super(input, options);
18
+ }
19
+ };
20
+ Object.defineProperty(global, "Request", {
21
+ value: Request
22
+ });
7
23
  var newRequestFromIncoming = (method, url, incoming) => {
8
24
  const headerRecord = [];
9
- const len = incoming.rawHeaders.length;
10
- for (let i = 0; i < len; i += 2) {
11
- headerRecord.push([incoming.rawHeaders[i], incoming.rawHeaders[i + 1]]);
25
+ const rawHeaders = incoming.rawHeaders;
26
+ for (let i = 0; i < rawHeaders.length; i += 2) {
27
+ const { [i]: key, [i + 1]: value } = rawHeaders;
28
+ if (key.charCodeAt(0) !== /*:*/
29
+ 58) {
30
+ headerRecord.push([key, value]);
31
+ }
12
32
  }
13
33
  const init = {
14
34
  method,
@@ -16,28 +36,26 @@ var newRequestFromIncoming = (method, url, incoming) => {
16
36
  };
17
37
  if (!(method === "GET" || method === "HEAD")) {
18
38
  init.body = Readable.toWeb(incoming);
19
- init.duplex = "half";
20
39
  }
21
40
  return new Request(url, init);
22
41
  };
23
42
  var getRequestCache = Symbol("getRequestCache");
24
43
  var requestCache = Symbol("requestCache");
25
44
  var incomingKey = Symbol("incomingKey");
45
+ var urlKey = Symbol("urlKey");
26
46
  var requestPrototype = {
27
47
  get method() {
28
48
  return this[incomingKey].method || "GET";
29
49
  },
30
50
  get url() {
31
- let path = this[incomingKey]["path"];
32
- if (!path) {
33
- const originalPath = this[incomingKey].url;
34
- path = /\.\./.test(originalPath) ? resolve(originalPath) : originalPath;
35
- this[incomingKey]["path"] = path;
36
- }
37
- return `http://${this[incomingKey].headers.host}${path}`;
51
+ return this[urlKey];
38
52
  },
39
53
  [getRequestCache]() {
40
- return this[requestCache] ||= newRequestFromIncoming(this.method, this.url, this[incomingKey]);
54
+ return this[requestCache] ||= newRequestFromIncoming(
55
+ this.method,
56
+ this[urlKey],
57
+ this[incomingKey]
58
+ );
41
59
  }
42
60
  };
43
61
  [
@@ -67,10 +85,13 @@ var requestPrototype = {
67
85
  }
68
86
  });
69
87
  });
70
- Object.setPrototypeOf(requestPrototype, global.Request.prototype);
88
+ Object.setPrototypeOf(requestPrototype, Request.prototype);
71
89
  var newRequest = (incoming) => {
72
90
  const req = Object.create(requestPrototype);
73
91
  req[incomingKey] = incoming;
92
+ req[urlKey] = new URL(
93
+ `http://${incoming instanceof Http2ServerRequest ? incoming.authority : incoming.headers.host}${incoming.url}`
94
+ ).href;
74
95
  return req;
75
96
  };
76
97
 
@@ -93,8 +114,9 @@ function writeFromReadableStream(stream, writable) {
93
114
  function cancel(error) {
94
115
  reader.cancel(error).catch(() => {
95
116
  });
96
- if (error)
117
+ if (error) {
97
118
  writable.destroy(error);
119
+ }
98
120
  }
99
121
  function onDrain() {
100
122
  reader.read().then(flow, cancel);
@@ -198,9 +220,6 @@ Object.defineProperty(global, "Response", {
198
220
 
199
221
  // src/globals.ts
200
222
  import crypto from "crypto";
201
- Object.defineProperty(global, "Response", {
202
- value: Response2
203
- });
204
223
  var webFetch = global.fetch;
205
224
  if (typeof global.crypto === "undefined") {
206
225
  global.crypto = crypto;
@@ -227,8 +246,9 @@ var handleResponseError = (e, outgoing) => {
227
246
  console.info("The user aborted a request.");
228
247
  } else {
229
248
  console.error(e);
230
- if (!outgoing.headersSent)
249
+ if (!outgoing.headersSent) {
231
250
  outgoing.writeHead(500, { "Content-Type": "text/plain" });
251
+ }
232
252
  outgoing.end(`Error: ${err.message}`);
233
253
  outgoing.destroy(err);
234
254
  }
@@ -247,11 +267,10 @@ var responseViaCache = (res, outgoing) => {
247
267
  }
248
268
  };
249
269
  var responseViaResponseObject = async (res, outgoing) => {
250
- if (res instanceof Promise) {
251
- res = await res.catch(handleFetchError);
252
- }
270
+ res = res instanceof Promise ? await res.catch(handleFetchError) : res;
253
271
  try {
254
- if (cacheKey in res) {
272
+ const isCached = cacheKey in res;
273
+ if (isCached) {
255
274
  return responseViaCache(res, outgoing);
256
275
  }
257
276
  } catch (e) {
@@ -260,8 +279,15 @@ var responseViaResponseObject = async (res, outgoing) => {
260
279
  const resHeaderRecord = buildOutgoingHttpHeaders(res.headers);
261
280
  if (res.body) {
262
281
  try {
263
- if (resHeaderRecord["transfer-encoding"] || resHeaderRecord["content-encoding"] || resHeaderRecord["content-length"] || // nginx buffering variant
264
- resHeaderRecord["x-accel-buffering"] && regBuffer.test(resHeaderRecord["x-accel-buffering"]) || !regContentType.test(resHeaderRecord["content-type"])) {
282
+ const {
283
+ "transfer-encoding": transferEncoding,
284
+ "content-encoding": contentEncoding,
285
+ "content-length": contentLength,
286
+ "x-accel-buffering": accelBuffering,
287
+ "content-type": contentType
288
+ } = resHeaderRecord;
289
+ if (transferEncoding || contentEncoding || contentLength || // nginx buffering variant
290
+ accelBuffering && regBuffer.test(accelBuffering) || !regContentType.test(contentType)) {
265
291
  outgoing.writeHead(res.status, resHeaderRecord);
266
292
  await writeFromReadableStream(res.body, outgoing);
267
293
  } else {
@@ -283,7 +309,7 @@ var getRequestListener = (fetchCallback) => {
283
309
  let res;
284
310
  const req = newRequest(incoming);
285
311
  try {
286
- res = fetchCallback(req);
312
+ res = fetchCallback(req, { incoming, outgoing });
287
313
  if (cacheKey in res) {
288
314
  return responseViaCache(res, outgoing);
289
315
  }
package/dist/types.d.mts CHANGED
@@ -1,8 +1,16 @@
1
- import { Server, ServerOptions as ServerOptions$1, createServer } from 'node:http';
2
- import { Http2Server, Http2SecureServer, ServerOptions as ServerOptions$3, createServer as createServer$2, SecureServerOptions, createSecureServer } 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
- type FetchCallback = (request: Request) => Promise<unknown> | unknown;
5
+ type HttpBindings = {
6
+ incoming: IncomingMessage;
7
+ outgoing: ServerResponse;
8
+ };
9
+ type Http2Bindings = {
10
+ incoming: Http2ServerRequest;
11
+ outgoing: Http2ServerResponse;
12
+ };
13
+ type FetchCallback = (request: Request, env: HttpBindings | Http2Bindings) => Promise<unknown> | unknown;
6
14
  type NextHandlerOption = {
7
15
  fetch: FetchCallback;
8
16
  };
@@ -30,4 +38,4 @@ type Options = {
30
38
  hostname?: string;
31
39
  } & ServerOptions;
32
40
 
33
- export { FetchCallback, NextHandlerOption, Options, ServerType };
41
+ export { FetchCallback, Http2Bindings, HttpBindings, NextHandlerOption, Options, ServerType };
package/dist/types.d.ts CHANGED
@@ -1,8 +1,16 @@
1
- import { Server, ServerOptions as ServerOptions$1, createServer } from 'node:http';
2
- import { Http2Server, Http2SecureServer, ServerOptions as ServerOptions$3, createServer as createServer$2, SecureServerOptions, createSecureServer } 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
- type FetchCallback = (request: Request) => Promise<unknown> | unknown;
5
+ type HttpBindings = {
6
+ incoming: IncomingMessage;
7
+ outgoing: ServerResponse;
8
+ };
9
+ type Http2Bindings = {
10
+ incoming: Http2ServerRequest;
11
+ outgoing: Http2ServerResponse;
12
+ };
13
+ type FetchCallback = (request: Request, env: HttpBindings | Http2Bindings) => Promise<unknown> | unknown;
6
14
  type NextHandlerOption = {
7
15
  fetch: FetchCallback;
8
16
  };
@@ -30,4 +38,4 @@ type Options = {
30
38
  hostname?: string;
31
39
  } & ServerOptions;
32
40
 
33
- export { FetchCallback, NextHandlerOption, Options, ServerType };
41
+ export { FetchCallback, Http2Bindings, HttpBindings, NextHandlerOption, Options, ServerType };
package/dist/utils.js CHANGED
@@ -42,8 +42,9 @@ function writeFromReadableStream(stream, writable) {
42
42
  function cancel(error) {
43
43
  reader.cancel(error).catch(() => {
44
44
  });
45
- if (error)
45
+ if (error) {
46
46
  writable.destroy(error);
47
+ }
47
48
  }
48
49
  function onDrain() {
49
50
  reader.read().then(flow, cancel);
package/dist/utils.mjs CHANGED
@@ -17,8 +17,9 @@ function writeFromReadableStream(stream, writable) {
17
17
  function cancel(error) {
18
18
  reader.cancel(error).catch(() => {
19
19
  });
20
- if (error)
20
+ if (error) {
21
21
  writable.destroy(error);
22
+ }
22
23
  }
23
24
  function onDrain() {
24
25
  reader.read().then(flow, cancel);
package/dist/vercel.js CHANGED
@@ -35,13 +35,33 @@ __export(vercel_exports, {
35
35
  module.exports = __toCommonJS(vercel_exports);
36
36
 
37
37
  // src/request.ts
38
- var import_node_path = require("path");
38
+ var import_node_http2 = require("http2");
39
39
  var import_node_stream = require("stream");
40
+ var GlobalRequest = global.Request;
41
+ var Request = class extends GlobalRequest {
42
+ constructor(input, options) {
43
+ if (typeof input === "object" && getRequestCache in input) {
44
+ input = input[getRequestCache]();
45
+ }
46
+ if (options?.body instanceof ReadableStream) {
47
+ ;
48
+ options.duplex = "half";
49
+ }
50
+ super(input, options);
51
+ }
52
+ };
53
+ Object.defineProperty(global, "Request", {
54
+ value: Request
55
+ });
40
56
  var newRequestFromIncoming = (method, url, incoming) => {
41
57
  const headerRecord = [];
42
- const len = incoming.rawHeaders.length;
43
- for (let i = 0; i < len; i += 2) {
44
- headerRecord.push([incoming.rawHeaders[i], incoming.rawHeaders[i + 1]]);
58
+ const rawHeaders = incoming.rawHeaders;
59
+ for (let i = 0; i < rawHeaders.length; i += 2) {
60
+ const { [i]: key, [i + 1]: value } = rawHeaders;
61
+ if (key.charCodeAt(0) !== /*:*/
62
+ 58) {
63
+ headerRecord.push([key, value]);
64
+ }
45
65
  }
46
66
  const init = {
47
67
  method,
@@ -49,28 +69,26 @@ var newRequestFromIncoming = (method, url, incoming) => {
49
69
  };
50
70
  if (!(method === "GET" || method === "HEAD")) {
51
71
  init.body = import_node_stream.Readable.toWeb(incoming);
52
- init.duplex = "half";
53
72
  }
54
73
  return new Request(url, init);
55
74
  };
56
75
  var getRequestCache = Symbol("getRequestCache");
57
76
  var requestCache = Symbol("requestCache");
58
77
  var incomingKey = Symbol("incomingKey");
78
+ var urlKey = Symbol("urlKey");
59
79
  var requestPrototype = {
60
80
  get method() {
61
81
  return this[incomingKey].method || "GET";
62
82
  },
63
83
  get url() {
64
- let path = this[incomingKey]["path"];
65
- if (!path) {
66
- const originalPath = this[incomingKey].url;
67
- path = /\.\./.test(originalPath) ? (0, import_node_path.resolve)(originalPath) : originalPath;
68
- this[incomingKey]["path"] = path;
69
- }
70
- return `http://${this[incomingKey].headers.host}${path}`;
84
+ return this[urlKey];
71
85
  },
72
86
  [getRequestCache]() {
73
- return this[requestCache] ||= newRequestFromIncoming(this.method, this.url, this[incomingKey]);
87
+ return this[requestCache] ||= newRequestFromIncoming(
88
+ this.method,
89
+ this[urlKey],
90
+ this[incomingKey]
91
+ );
74
92
  }
75
93
  };
76
94
  [
@@ -100,10 +118,13 @@ var requestPrototype = {
100
118
  }
101
119
  });
102
120
  });
103
- Object.setPrototypeOf(requestPrototype, global.Request.prototype);
121
+ Object.setPrototypeOf(requestPrototype, Request.prototype);
104
122
  var newRequest = (incoming) => {
105
123
  const req = Object.create(requestPrototype);
106
124
  req[incomingKey] = incoming;
125
+ req[urlKey] = new URL(
126
+ `http://${incoming instanceof import_node_http2.Http2ServerRequest ? incoming.authority : incoming.headers.host}${incoming.url}`
127
+ ).href;
107
128
  return req;
108
129
  };
109
130
 
@@ -126,8 +147,9 @@ function writeFromReadableStream(stream, writable) {
126
147
  function cancel(error) {
127
148
  reader.cancel(error).catch(() => {
128
149
  });
129
- if (error)
150
+ if (error) {
130
151
  writable.destroy(error);
152
+ }
131
153
  }
132
154
  function onDrain() {
133
155
  reader.read().then(flow, cancel);
@@ -231,9 +253,6 @@ Object.defineProperty(global, "Response", {
231
253
 
232
254
  // src/globals.ts
233
255
  var import_node_crypto = __toESM(require("crypto"));
234
- Object.defineProperty(global, "Response", {
235
- value: Response2
236
- });
237
256
  var webFetch = global.fetch;
238
257
  if (typeof global.crypto === "undefined") {
239
258
  global.crypto = import_node_crypto.default;
@@ -260,8 +279,9 @@ var handleResponseError = (e, outgoing) => {
260
279
  console.info("The user aborted a request.");
261
280
  } else {
262
281
  console.error(e);
263
- if (!outgoing.headersSent)
282
+ if (!outgoing.headersSent) {
264
283
  outgoing.writeHead(500, { "Content-Type": "text/plain" });
284
+ }
265
285
  outgoing.end(`Error: ${err.message}`);
266
286
  outgoing.destroy(err);
267
287
  }
@@ -280,11 +300,10 @@ var responseViaCache = (res, outgoing) => {
280
300
  }
281
301
  };
282
302
  var responseViaResponseObject = async (res, outgoing) => {
283
- if (res instanceof Promise) {
284
- res = await res.catch(handleFetchError);
285
- }
303
+ res = res instanceof Promise ? await res.catch(handleFetchError) : res;
286
304
  try {
287
- if (cacheKey in res) {
305
+ const isCached = cacheKey in res;
306
+ if (isCached) {
288
307
  return responseViaCache(res, outgoing);
289
308
  }
290
309
  } catch (e) {
@@ -293,8 +312,15 @@ var responseViaResponseObject = async (res, outgoing) => {
293
312
  const resHeaderRecord = buildOutgoingHttpHeaders(res.headers);
294
313
  if (res.body) {
295
314
  try {
296
- if (resHeaderRecord["transfer-encoding"] || resHeaderRecord["content-encoding"] || resHeaderRecord["content-length"] || // nginx buffering variant
297
- resHeaderRecord["x-accel-buffering"] && regBuffer.test(resHeaderRecord["x-accel-buffering"]) || !regContentType.test(resHeaderRecord["content-type"])) {
315
+ const {
316
+ "transfer-encoding": transferEncoding,
317
+ "content-encoding": contentEncoding,
318
+ "content-length": contentLength,
319
+ "x-accel-buffering": accelBuffering,
320
+ "content-type": contentType
321
+ } = resHeaderRecord;
322
+ if (transferEncoding || contentEncoding || contentLength || // nginx buffering variant
323
+ accelBuffering && regBuffer.test(accelBuffering) || !regContentType.test(contentType)) {
298
324
  outgoing.writeHead(res.status, resHeaderRecord);
299
325
  await writeFromReadableStream(res.body, outgoing);
300
326
  } else {
@@ -316,7 +342,7 @@ var getRequestListener = (fetchCallback) => {
316
342
  let res;
317
343
  const req = newRequest(incoming);
318
344
  try {
319
- res = fetchCallback(req);
345
+ res = fetchCallback(req, { incoming, outgoing });
320
346
  if (cacheKey in res) {
321
347
  return responseViaCache(res, outgoing);
322
348
  }
package/dist/vercel.mjs CHANGED
@@ -1,11 +1,31 @@
1
1
  // src/request.ts
2
- import { resolve } from "path";
2
+ import { Http2ServerRequest } from "http2";
3
3
  import { Readable } from "stream";
4
+ var GlobalRequest = global.Request;
5
+ var Request = class extends GlobalRequest {
6
+ constructor(input, options) {
7
+ if (typeof input === "object" && getRequestCache in input) {
8
+ input = input[getRequestCache]();
9
+ }
10
+ if (options?.body instanceof ReadableStream) {
11
+ ;
12
+ options.duplex = "half";
13
+ }
14
+ super(input, options);
15
+ }
16
+ };
17
+ Object.defineProperty(global, "Request", {
18
+ value: Request
19
+ });
4
20
  var newRequestFromIncoming = (method, url, incoming) => {
5
21
  const headerRecord = [];
6
- const len = incoming.rawHeaders.length;
7
- for (let i = 0; i < len; i += 2) {
8
- headerRecord.push([incoming.rawHeaders[i], incoming.rawHeaders[i + 1]]);
22
+ const rawHeaders = incoming.rawHeaders;
23
+ for (let i = 0; i < rawHeaders.length; i += 2) {
24
+ const { [i]: key, [i + 1]: value } = rawHeaders;
25
+ if (key.charCodeAt(0) !== /*:*/
26
+ 58) {
27
+ headerRecord.push([key, value]);
28
+ }
9
29
  }
10
30
  const init = {
11
31
  method,
@@ -13,28 +33,26 @@ var newRequestFromIncoming = (method, url, incoming) => {
13
33
  };
14
34
  if (!(method === "GET" || method === "HEAD")) {
15
35
  init.body = Readable.toWeb(incoming);
16
- init.duplex = "half";
17
36
  }
18
37
  return new Request(url, init);
19
38
  };
20
39
  var getRequestCache = Symbol("getRequestCache");
21
40
  var requestCache = Symbol("requestCache");
22
41
  var incomingKey = Symbol("incomingKey");
42
+ var urlKey = Symbol("urlKey");
23
43
  var requestPrototype = {
24
44
  get method() {
25
45
  return this[incomingKey].method || "GET";
26
46
  },
27
47
  get url() {
28
- let path = this[incomingKey]["path"];
29
- if (!path) {
30
- const originalPath = this[incomingKey].url;
31
- path = /\.\./.test(originalPath) ? resolve(originalPath) : originalPath;
32
- this[incomingKey]["path"] = path;
33
- }
34
- return `http://${this[incomingKey].headers.host}${path}`;
48
+ return this[urlKey];
35
49
  },
36
50
  [getRequestCache]() {
37
- return this[requestCache] ||= newRequestFromIncoming(this.method, this.url, this[incomingKey]);
51
+ return this[requestCache] ||= newRequestFromIncoming(
52
+ this.method,
53
+ this[urlKey],
54
+ this[incomingKey]
55
+ );
38
56
  }
39
57
  };
40
58
  [
@@ -64,10 +82,13 @@ var requestPrototype = {
64
82
  }
65
83
  });
66
84
  });
67
- Object.setPrototypeOf(requestPrototype, global.Request.prototype);
85
+ Object.setPrototypeOf(requestPrototype, Request.prototype);
68
86
  var newRequest = (incoming) => {
69
87
  const req = Object.create(requestPrototype);
70
88
  req[incomingKey] = incoming;
89
+ req[urlKey] = new URL(
90
+ `http://${incoming instanceof Http2ServerRequest ? incoming.authority : incoming.headers.host}${incoming.url}`
91
+ ).href;
71
92
  return req;
72
93
  };
73
94
 
@@ -90,8 +111,9 @@ function writeFromReadableStream(stream, writable) {
90
111
  function cancel(error) {
91
112
  reader.cancel(error).catch(() => {
92
113
  });
93
- if (error)
114
+ if (error) {
94
115
  writable.destroy(error);
116
+ }
95
117
  }
96
118
  function onDrain() {
97
119
  reader.read().then(flow, cancel);
@@ -195,9 +217,6 @@ Object.defineProperty(global, "Response", {
195
217
 
196
218
  // src/globals.ts
197
219
  import crypto from "crypto";
198
- Object.defineProperty(global, "Response", {
199
- value: Response2
200
- });
201
220
  var webFetch = global.fetch;
202
221
  if (typeof global.crypto === "undefined") {
203
222
  global.crypto = crypto;
@@ -224,8 +243,9 @@ var handleResponseError = (e, outgoing) => {
224
243
  console.info("The user aborted a request.");
225
244
  } else {
226
245
  console.error(e);
227
- if (!outgoing.headersSent)
246
+ if (!outgoing.headersSent) {
228
247
  outgoing.writeHead(500, { "Content-Type": "text/plain" });
248
+ }
229
249
  outgoing.end(`Error: ${err.message}`);
230
250
  outgoing.destroy(err);
231
251
  }
@@ -244,11 +264,10 @@ var responseViaCache = (res, outgoing) => {
244
264
  }
245
265
  };
246
266
  var responseViaResponseObject = async (res, outgoing) => {
247
- if (res instanceof Promise) {
248
- res = await res.catch(handleFetchError);
249
- }
267
+ res = res instanceof Promise ? await res.catch(handleFetchError) : res;
250
268
  try {
251
- if (cacheKey in res) {
269
+ const isCached = cacheKey in res;
270
+ if (isCached) {
252
271
  return responseViaCache(res, outgoing);
253
272
  }
254
273
  } catch (e) {
@@ -257,8 +276,15 @@ var responseViaResponseObject = async (res, outgoing) => {
257
276
  const resHeaderRecord = buildOutgoingHttpHeaders(res.headers);
258
277
  if (res.body) {
259
278
  try {
260
- if (resHeaderRecord["transfer-encoding"] || resHeaderRecord["content-encoding"] || resHeaderRecord["content-length"] || // nginx buffering variant
261
- resHeaderRecord["x-accel-buffering"] && regBuffer.test(resHeaderRecord["x-accel-buffering"]) || !regContentType.test(resHeaderRecord["content-type"])) {
279
+ const {
280
+ "transfer-encoding": transferEncoding,
281
+ "content-encoding": contentEncoding,
282
+ "content-length": contentLength,
283
+ "x-accel-buffering": accelBuffering,
284
+ "content-type": contentType
285
+ } = resHeaderRecord;
286
+ if (transferEncoding || contentEncoding || contentLength || // nginx buffering variant
287
+ accelBuffering && regBuffer.test(accelBuffering) || !regContentType.test(contentType)) {
262
288
  outgoing.writeHead(res.status, resHeaderRecord);
263
289
  await writeFromReadableStream(res.body, outgoing);
264
290
  } else {
@@ -280,7 +306,7 @@ var getRequestListener = (fetchCallback) => {
280
306
  let res;
281
307
  const req = newRequest(incoming);
282
308
  try {
283
- res = fetchCallback(req);
309
+ res = fetchCallback(req, { incoming, outgoing });
284
310
  if (cacheKey in res) {
285
311
  return responseViaCache(res, outgoing);
286
312
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hono/node-server",
3
- "version": "1.4.1",
3
+ "version": "1.6.0",
4
4
  "description": "Node.js Adapter for Hono",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -45,7 +45,9 @@
45
45
  "prerelease": "yarn build && yarn test",
46
46
  "release": "np",
47
47
  "lint": "eslint --ext js,ts src test",
48
- "lint:fix": "eslint --ext js,ts src test --fix"
48
+ "lint:fix": "eslint --ext js,ts src test --fix",
49
+ "format": "prettier --check \"src/**/*.{js,ts}\" \"test/**/*.{js,ts}\"",
50
+ "format:fix": "prettier --write \"src/**/*.{js,ts}\" \"test/**/*.{js,ts}\""
49
51
  },
50
52
  "license": "MIT",
51
53
  "repository": {
@@ -62,7 +64,7 @@
62
64
  "node": ">=18.14.1"
63
65
  },
64
66
  "devDependencies": {
65
- "@hono/eslint-config": "^0.0.2",
67
+ "@hono/eslint-config": "^0.0.4",
66
68
  "@types/jest": "^29.5.3",
67
69
  "@types/node": "^20.10.0",
68
70
  "@types/supertest": "^2.0.12",
@@ -71,6 +73,7 @@
71
73
  "hono": "^3.11.7",
72
74
  "jest": "^29.6.1",
73
75
  "np": "^7.7.0",
76
+ "prettier": "^3.2.4",
74
77
  "publint": "^0.1.16",
75
78
  "supertest": "^6.3.3",
76
79
  "ts-jest": "^29.1.1",