@hono/node-server 1.7.0 → 1.8.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/listener.mjs CHANGED
@@ -17,7 +17,7 @@ var Request = class extends GlobalRequest {
17
17
  Object.defineProperty(global, "Request", {
18
18
  value: Request
19
19
  });
20
- var newRequestFromIncoming = (method, url, incoming) => {
20
+ var newRequestFromIncoming = (method, url, incoming, abortController) => {
21
21
  const headerRecord = [];
22
22
  const rawHeaders = incoming.rawHeaders;
23
23
  for (let i = 0; i < rawHeaders.length; i += 2) {
@@ -29,7 +29,8 @@ var newRequestFromIncoming = (method, url, incoming) => {
29
29
  }
30
30
  const init = {
31
31
  method,
32
- headers: headerRecord
32
+ headers: headerRecord,
33
+ signal: abortController.signal
33
34
  };
34
35
  if (!(method === "GET" || method === "HEAD")) {
35
36
  init.body = Readable.toWeb(incoming);
@@ -40,6 +41,8 @@ var getRequestCache = Symbol("getRequestCache");
40
41
  var requestCache = Symbol("requestCache");
41
42
  var incomingKey = Symbol("incomingKey");
42
43
  var urlKey = Symbol("urlKey");
44
+ var abortControllerKey = Symbol("abortControllerKey");
45
+ var getAbortController = Symbol("getAbortController");
43
46
  var requestPrototype = {
44
47
  get method() {
45
48
  return this[incomingKey].method || "GET";
@@ -47,11 +50,17 @@ var requestPrototype = {
47
50
  get url() {
48
51
  return this[urlKey];
49
52
  },
53
+ [getAbortController]() {
54
+ this[getRequestCache]();
55
+ return this[abortControllerKey];
56
+ },
50
57
  [getRequestCache]() {
58
+ this[abortControllerKey] ||= new AbortController();
51
59
  return this[requestCache] ||= newRequestFromIncoming(
52
60
  this.method,
53
61
  this[urlKey],
54
- this[incomingKey]
62
+ this[incomingKey],
63
+ this[abortControllerKey]
55
64
  );
56
65
  }
57
66
  };
@@ -145,18 +154,19 @@ var buildOutgoingHttpHeaders = (headers) => {
145
154
  if (cookies.length > 0) {
146
155
  res["set-cookie"] = cookies;
147
156
  }
148
- res["content-type"] ??= "text/plain;charset=UTF-8";
157
+ res["content-type"] ??= "text/plain; charset=UTF-8";
149
158
  return res;
150
159
  };
151
160
 
152
161
  // src/response.ts
153
162
  var responseCache = Symbol("responseCache");
163
+ var getResponseCache = Symbol("getResponseCache");
154
164
  var cacheKey = Symbol("cache");
155
165
  var GlobalResponse = global.Response;
156
166
  var Response2 = class _Response {
157
167
  #body;
158
168
  #init;
159
- get cache() {
169
+ [getResponseCache]() {
160
170
  delete this[cacheKey];
161
171
  return this[responseCache] ||= new GlobalResponse(this.#body, this.#init);
162
172
  }
@@ -166,7 +176,7 @@ var Response2 = class _Response {
166
176
  const cachedGlobalResponse = init[responseCache];
167
177
  if (cachedGlobalResponse) {
168
178
  this.#init = cachedGlobalResponse;
169
- this.cache;
179
+ this[getResponseCache]();
170
180
  return;
171
181
  } else {
172
182
  this.#init = init.#init;
@@ -175,7 +185,7 @@ var Response2 = class _Response {
175
185
  this.#init = init;
176
186
  }
177
187
  if (typeof body === "string" || body instanceof ReadableStream) {
178
- let headers = init?.headers || { "content-type": "text/plain;charset=UTF-8" };
188
+ let headers = init?.headers || { "content-type": "text/plain; charset=UTF-8" };
179
189
  if (headers instanceof Headers) {
180
190
  headers = buildOutgoingHttpHeaders(headers);
181
191
  }
@@ -198,14 +208,14 @@ var Response2 = class _Response {
198
208
  ].forEach((k) => {
199
209
  Object.defineProperty(Response2.prototype, k, {
200
210
  get() {
201
- return this.cache[k];
211
+ return this[getResponseCache]()[k];
202
212
  }
203
213
  });
204
214
  });
205
215
  ["arrayBuffer", "blob", "clone", "formData", "json", "text"].forEach((k) => {
206
216
  Object.defineProperty(Response2.prototype, k, {
207
217
  value: function() {
208
- return this.cache[k]();
218
+ return this[getResponseCache]()[k]();
209
219
  }
210
220
  });
211
221
  });
@@ -214,6 +224,22 @@ Object.setPrototypeOf(Response2.prototype, GlobalResponse.prototype);
214
224
  Object.defineProperty(global, "Response", {
215
225
  value: Response2
216
226
  });
227
+ var stateKey = Reflect.ownKeys(new GlobalResponse()).find(
228
+ (k) => typeof k === "symbol" && k.toString() === "Symbol(state)"
229
+ );
230
+ if (!stateKey) {
231
+ console.warn("Failed to find Response internal state key");
232
+ }
233
+ function getInternalBody(response) {
234
+ if (!stateKey) {
235
+ return;
236
+ }
237
+ if (response instanceof Response2) {
238
+ response = response[getResponseCache]();
239
+ }
240
+ const state = response[stateKey];
241
+ return state && state.body || void 0;
242
+ }
217
243
 
218
244
  // src/globals.ts
219
245
  import crypto from "crypto";
@@ -279,36 +305,40 @@ var responseViaResponseObject = async (res, outgoing, options = {}) => {
279
305
  res = await res.catch(handleFetchError);
280
306
  }
281
307
  }
282
- try {
283
- const isCached = cacheKey in res;
284
- if (isCached) {
285
- return responseViaCache(res, outgoing);
286
- }
287
- } catch (e) {
288
- return handleResponseError(e, outgoing);
308
+ if (cacheKey in res) {
309
+ return responseViaCache(res, outgoing);
289
310
  }
290
311
  const resHeaderRecord = buildOutgoingHttpHeaders(res.headers);
291
- if (res.body) {
292
- try {
293
- const {
294
- "transfer-encoding": transferEncoding,
295
- "content-encoding": contentEncoding,
296
- "content-length": contentLength,
297
- "x-accel-buffering": accelBuffering,
298
- "content-type": contentType
299
- } = resHeaderRecord;
300
- if (transferEncoding || contentEncoding || contentLength || // nginx buffering variant
301
- accelBuffering && regBuffer.test(accelBuffering) || !regContentType.test(contentType)) {
302
- outgoing.writeHead(res.status, resHeaderRecord);
303
- await writeFromReadableStream(res.body, outgoing);
304
- } else {
305
- const buffer = await res.arrayBuffer();
306
- resHeaderRecord["content-length"] = buffer.byteLength;
307
- outgoing.writeHead(res.status, resHeaderRecord);
308
- outgoing.end(new Uint8Array(buffer));
309
- }
310
- } catch (e) {
311
- handleResponseError(e, outgoing);
312
+ const internalBody = getInternalBody(res);
313
+ if (internalBody) {
314
+ if (internalBody.length) {
315
+ resHeaderRecord["content-length"] = internalBody.length;
316
+ }
317
+ outgoing.writeHead(res.status, resHeaderRecord);
318
+ if (typeof internalBody.source === "string" || internalBody.source instanceof Uint8Array) {
319
+ outgoing.end(internalBody.source);
320
+ } else if (internalBody.source instanceof Blob) {
321
+ outgoing.end(new Uint8Array(await internalBody.source.arrayBuffer()));
322
+ } else {
323
+ await writeFromReadableStream(internalBody.stream, outgoing);
324
+ }
325
+ } else if (res.body) {
326
+ const {
327
+ "transfer-encoding": transferEncoding,
328
+ "content-encoding": contentEncoding,
329
+ "content-length": contentLength,
330
+ "x-accel-buffering": accelBuffering,
331
+ "content-type": contentType
332
+ } = resHeaderRecord;
333
+ if (transferEncoding || contentEncoding || contentLength || // nginx buffering variant
334
+ accelBuffering && regBuffer.test(accelBuffering) || !regContentType.test(contentType)) {
335
+ outgoing.writeHead(res.status, resHeaderRecord);
336
+ await writeFromReadableStream(res.body, outgoing);
337
+ } else {
338
+ const buffer = await res.arrayBuffer();
339
+ resHeaderRecord["content-length"] = buffer.byteLength;
340
+ outgoing.writeHead(res.status, resHeaderRecord);
341
+ outgoing.end(new Uint8Array(buffer));
312
342
  }
313
343
  } else {
314
344
  outgoing.writeHead(res.status, resHeaderRecord);
@@ -319,6 +349,11 @@ var getRequestListener = (fetchCallback, options = {}) => {
319
349
  return async (incoming, outgoing) => {
320
350
  let res;
321
351
  const req = newRequest(incoming);
352
+ outgoing.on("close", () => {
353
+ if (incoming.destroyed) {
354
+ req[getAbortController]().abort();
355
+ }
356
+ });
322
357
  try {
323
358
  res = fetchCallback(req, { incoming, outgoing });
324
359
  if (cacheKey in res) {
@@ -338,7 +373,11 @@ var getRequestListener = (fetchCallback, options = {}) => {
338
373
  return handleResponseError(e, outgoing);
339
374
  }
340
375
  }
341
- return responseViaResponseObject(res, outgoing, options);
376
+ try {
377
+ return responseViaResponseObject(res, outgoing, options);
378
+ } catch (e) {
379
+ return handleResponseError(e, outgoing);
380
+ }
342
381
  };
343
382
  };
344
383
  export {
@@ -8,6 +8,7 @@ declare const GlobalRequest: {
8
8
  declare class Request extends GlobalRequest {
9
9
  constructor(input: string | Request, options?: RequestInit);
10
10
  }
11
+ declare const getAbortController: unique symbol;
11
12
  declare const newRequest: (incoming: IncomingMessage | Http2ServerRequest) => any;
12
13
 
13
- export { GlobalRequest, Request, newRequest };
14
+ export { GlobalRequest, Request, getAbortController, newRequest };
package/dist/request.d.ts CHANGED
@@ -8,6 +8,7 @@ declare const GlobalRequest: {
8
8
  declare class Request extends GlobalRequest {
9
9
  constructor(input: string | Request, options?: RequestInit);
10
10
  }
11
+ declare const getAbortController: unique symbol;
11
12
  declare const newRequest: (incoming: IncomingMessage | Http2ServerRequest) => any;
12
13
 
13
- export { GlobalRequest, Request, newRequest };
14
+ export { GlobalRequest, Request, getAbortController, newRequest };
package/dist/request.js CHANGED
@@ -22,6 +22,7 @@ var request_exports = {};
22
22
  __export(request_exports, {
23
23
  GlobalRequest: () => GlobalRequest,
24
24
  Request: () => Request,
25
+ getAbortController: () => getAbortController,
25
26
  newRequest: () => newRequest
26
27
  });
27
28
  module.exports = __toCommonJS(request_exports);
@@ -43,7 +44,7 @@ var Request = class extends GlobalRequest {
43
44
  Object.defineProperty(global, "Request", {
44
45
  value: Request
45
46
  });
46
- var newRequestFromIncoming = (method, url, incoming) => {
47
+ var newRequestFromIncoming = (method, url, incoming, abortController) => {
47
48
  const headerRecord = [];
48
49
  const rawHeaders = incoming.rawHeaders;
49
50
  for (let i = 0; i < rawHeaders.length; i += 2) {
@@ -55,7 +56,8 @@ var newRequestFromIncoming = (method, url, incoming) => {
55
56
  }
56
57
  const init = {
57
58
  method,
58
- headers: headerRecord
59
+ headers: headerRecord,
60
+ signal: abortController.signal
59
61
  };
60
62
  if (!(method === "GET" || method === "HEAD")) {
61
63
  init.body = import_node_stream.Readable.toWeb(incoming);
@@ -66,6 +68,8 @@ var getRequestCache = Symbol("getRequestCache");
66
68
  var requestCache = Symbol("requestCache");
67
69
  var incomingKey = Symbol("incomingKey");
68
70
  var urlKey = Symbol("urlKey");
71
+ var abortControllerKey = Symbol("abortControllerKey");
72
+ var getAbortController = Symbol("getAbortController");
69
73
  var requestPrototype = {
70
74
  get method() {
71
75
  return this[incomingKey].method || "GET";
@@ -73,11 +77,17 @@ var requestPrototype = {
73
77
  get url() {
74
78
  return this[urlKey];
75
79
  },
80
+ [getAbortController]() {
81
+ this[getRequestCache]();
82
+ return this[abortControllerKey];
83
+ },
76
84
  [getRequestCache]() {
85
+ this[abortControllerKey] ||= new AbortController();
77
86
  return this[requestCache] ||= newRequestFromIncoming(
78
87
  this.method,
79
88
  this[urlKey],
80
- this[incomingKey]
89
+ this[incomingKey],
90
+ this[abortControllerKey]
81
91
  );
82
92
  }
83
93
  };
@@ -121,5 +131,6 @@ var newRequest = (incoming) => {
121
131
  0 && (module.exports = {
122
132
  GlobalRequest,
123
133
  Request,
134
+ getAbortController,
124
135
  newRequest
125
136
  });
package/dist/request.mjs CHANGED
@@ -17,7 +17,7 @@ var Request = class extends GlobalRequest {
17
17
  Object.defineProperty(global, "Request", {
18
18
  value: Request
19
19
  });
20
- var newRequestFromIncoming = (method, url, incoming) => {
20
+ var newRequestFromIncoming = (method, url, incoming, abortController) => {
21
21
  const headerRecord = [];
22
22
  const rawHeaders = incoming.rawHeaders;
23
23
  for (let i = 0; i < rawHeaders.length; i += 2) {
@@ -29,7 +29,8 @@ var newRequestFromIncoming = (method, url, incoming) => {
29
29
  }
30
30
  const init = {
31
31
  method,
32
- headers: headerRecord
32
+ headers: headerRecord,
33
+ signal: abortController.signal
33
34
  };
34
35
  if (!(method === "GET" || method === "HEAD")) {
35
36
  init.body = Readable.toWeb(incoming);
@@ -40,6 +41,8 @@ var getRequestCache = Symbol("getRequestCache");
40
41
  var requestCache = Symbol("requestCache");
41
42
  var incomingKey = Symbol("incomingKey");
42
43
  var urlKey = Symbol("urlKey");
44
+ var abortControllerKey = Symbol("abortControllerKey");
45
+ var getAbortController = Symbol("getAbortController");
43
46
  var requestPrototype = {
44
47
  get method() {
45
48
  return this[incomingKey].method || "GET";
@@ -47,11 +50,17 @@ var requestPrototype = {
47
50
  get url() {
48
51
  return this[urlKey];
49
52
  },
53
+ [getAbortController]() {
54
+ this[getRequestCache]();
55
+ return this[abortControllerKey];
56
+ },
50
57
  [getRequestCache]() {
58
+ this[abortControllerKey] ||= new AbortController();
51
59
  return this[requestCache] ||= newRequestFromIncoming(
52
60
  this.method,
53
61
  this[urlKey],
54
- this[incomingKey]
62
+ this[incomingKey],
63
+ this[abortControllerKey]
55
64
  );
56
65
  }
57
66
  };
@@ -94,5 +103,6 @@ var newRequest = (incoming) => {
94
103
  export {
95
104
  GlobalRequest,
96
105
  Request,
106
+ getAbortController,
97
107
  newRequest
98
108
  };
@@ -1,3 +1,9 @@
1
+ interface InternalBody {
2
+ source: string | Uint8Array | FormData | Blob | null;
3
+ stream: ReadableStream;
4
+ length: number | null;
5
+ }
6
+ declare const getResponseCache: unique symbol;
1
7
  declare const cacheKey: unique symbol;
2
8
  declare const GlobalResponse: {
3
9
  new (body?: BodyInit | null | undefined, init?: ResponseInit | undefined): globalThis.Response;
@@ -8,8 +14,9 @@ declare const GlobalResponse: {
8
14
  };
9
15
  declare class Response {
10
16
  #private;
11
- private get cache();
17
+ [getResponseCache](): typeof GlobalResponse;
12
18
  constructor(body?: BodyInit | null, init?: ResponseInit);
13
19
  }
20
+ declare function getInternalBody(response: Response | typeof GlobalResponse): InternalBody | undefined;
14
21
 
15
- export { GlobalResponse, Response, cacheKey };
22
+ export { GlobalResponse, Response, cacheKey, getInternalBody };
@@ -1,3 +1,9 @@
1
+ interface InternalBody {
2
+ source: string | Uint8Array | FormData | Blob | null;
3
+ stream: ReadableStream;
4
+ length: number | null;
5
+ }
6
+ declare const getResponseCache: unique symbol;
1
7
  declare const cacheKey: unique symbol;
2
8
  declare const GlobalResponse: {
3
9
  new (body?: BodyInit | null | undefined, init?: ResponseInit | undefined): globalThis.Response;
@@ -8,8 +14,9 @@ declare const GlobalResponse: {
8
14
  };
9
15
  declare class Response {
10
16
  #private;
11
- private get cache();
17
+ [getResponseCache](): typeof GlobalResponse;
12
18
  constructor(body?: BodyInit | null, init?: ResponseInit);
13
19
  }
20
+ declare function getInternalBody(response: Response | typeof GlobalResponse): InternalBody | undefined;
14
21
 
15
- export { GlobalResponse, Response, cacheKey };
22
+ export { GlobalResponse, Response, cacheKey, getInternalBody };
package/dist/response.js CHANGED
@@ -22,7 +22,8 @@ var response_exports = {};
22
22
  __export(response_exports, {
23
23
  GlobalResponse: () => GlobalResponse,
24
24
  Response: () => Response,
25
- cacheKey: () => cacheKey
25
+ cacheKey: () => cacheKey,
26
+ getInternalBody: () => getInternalBody
26
27
  });
27
28
  module.exports = __toCommonJS(response_exports);
28
29
 
@@ -40,18 +41,19 @@ var buildOutgoingHttpHeaders = (headers) => {
40
41
  if (cookies.length > 0) {
41
42
  res["set-cookie"] = cookies;
42
43
  }
43
- res["content-type"] ??= "text/plain;charset=UTF-8";
44
+ res["content-type"] ??= "text/plain; charset=UTF-8";
44
45
  return res;
45
46
  };
46
47
 
47
48
  // src/response.ts
48
49
  var responseCache = Symbol("responseCache");
50
+ var getResponseCache = Symbol("getResponseCache");
49
51
  var cacheKey = Symbol("cache");
50
52
  var GlobalResponse = global.Response;
51
53
  var Response = class _Response {
52
54
  #body;
53
55
  #init;
54
- get cache() {
56
+ [getResponseCache]() {
55
57
  delete this[cacheKey];
56
58
  return this[responseCache] ||= new GlobalResponse(this.#body, this.#init);
57
59
  }
@@ -61,7 +63,7 @@ var Response = class _Response {
61
63
  const cachedGlobalResponse = init[responseCache];
62
64
  if (cachedGlobalResponse) {
63
65
  this.#init = cachedGlobalResponse;
64
- this.cache;
66
+ this[getResponseCache]();
65
67
  return;
66
68
  } else {
67
69
  this.#init = init.#init;
@@ -70,7 +72,7 @@ var Response = class _Response {
70
72
  this.#init = init;
71
73
  }
72
74
  if (typeof body === "string" || body instanceof ReadableStream) {
73
- let headers = init?.headers || { "content-type": "text/plain;charset=UTF-8" };
75
+ let headers = init?.headers || { "content-type": "text/plain; charset=UTF-8" };
74
76
  if (headers instanceof Headers) {
75
77
  headers = buildOutgoingHttpHeaders(headers);
76
78
  }
@@ -93,14 +95,14 @@ var Response = class _Response {
93
95
  ].forEach((k) => {
94
96
  Object.defineProperty(Response.prototype, k, {
95
97
  get() {
96
- return this.cache[k];
98
+ return this[getResponseCache]()[k];
97
99
  }
98
100
  });
99
101
  });
100
102
  ["arrayBuffer", "blob", "clone", "formData", "json", "text"].forEach((k) => {
101
103
  Object.defineProperty(Response.prototype, k, {
102
104
  value: function() {
103
- return this.cache[k]();
105
+ return this[getResponseCache]()[k]();
104
106
  }
105
107
  });
106
108
  });
@@ -109,9 +111,26 @@ Object.setPrototypeOf(Response.prototype, GlobalResponse.prototype);
109
111
  Object.defineProperty(global, "Response", {
110
112
  value: Response
111
113
  });
114
+ var stateKey = Reflect.ownKeys(new GlobalResponse()).find(
115
+ (k) => typeof k === "symbol" && k.toString() === "Symbol(state)"
116
+ );
117
+ if (!stateKey) {
118
+ console.warn("Failed to find Response internal state key");
119
+ }
120
+ function getInternalBody(response) {
121
+ if (!stateKey) {
122
+ return;
123
+ }
124
+ if (response instanceof Response) {
125
+ response = response[getResponseCache]();
126
+ }
127
+ const state = response[stateKey];
128
+ return state && state.body || void 0;
129
+ }
112
130
  // Annotate the CommonJS export names for ESM import in node:
113
131
  0 && (module.exports = {
114
132
  GlobalResponse,
115
133
  Response,
116
- cacheKey
134
+ cacheKey,
135
+ getInternalBody
117
136
  });
package/dist/response.mjs CHANGED
@@ -12,18 +12,19 @@ var buildOutgoingHttpHeaders = (headers) => {
12
12
  if (cookies.length > 0) {
13
13
  res["set-cookie"] = cookies;
14
14
  }
15
- res["content-type"] ??= "text/plain;charset=UTF-8";
15
+ res["content-type"] ??= "text/plain; charset=UTF-8";
16
16
  return res;
17
17
  };
18
18
 
19
19
  // src/response.ts
20
20
  var responseCache = Symbol("responseCache");
21
+ var getResponseCache = Symbol("getResponseCache");
21
22
  var cacheKey = Symbol("cache");
22
23
  var GlobalResponse = global.Response;
23
24
  var Response = class _Response {
24
25
  #body;
25
26
  #init;
26
- get cache() {
27
+ [getResponseCache]() {
27
28
  delete this[cacheKey];
28
29
  return this[responseCache] ||= new GlobalResponse(this.#body, this.#init);
29
30
  }
@@ -33,7 +34,7 @@ var Response = class _Response {
33
34
  const cachedGlobalResponse = init[responseCache];
34
35
  if (cachedGlobalResponse) {
35
36
  this.#init = cachedGlobalResponse;
36
- this.cache;
37
+ this[getResponseCache]();
37
38
  return;
38
39
  } else {
39
40
  this.#init = init.#init;
@@ -42,7 +43,7 @@ var Response = class _Response {
42
43
  this.#init = init;
43
44
  }
44
45
  if (typeof body === "string" || body instanceof ReadableStream) {
45
- let headers = init?.headers || { "content-type": "text/plain;charset=UTF-8" };
46
+ let headers = init?.headers || { "content-type": "text/plain; charset=UTF-8" };
46
47
  if (headers instanceof Headers) {
47
48
  headers = buildOutgoingHttpHeaders(headers);
48
49
  }
@@ -65,14 +66,14 @@ var Response = class _Response {
65
66
  ].forEach((k) => {
66
67
  Object.defineProperty(Response.prototype, k, {
67
68
  get() {
68
- return this.cache[k];
69
+ return this[getResponseCache]()[k];
69
70
  }
70
71
  });
71
72
  });
72
73
  ["arrayBuffer", "blob", "clone", "formData", "json", "text"].forEach((k) => {
73
74
  Object.defineProperty(Response.prototype, k, {
74
75
  value: function() {
75
- return this.cache[k]();
76
+ return this[getResponseCache]()[k]();
76
77
  }
77
78
  });
78
79
  });
@@ -81,8 +82,25 @@ Object.setPrototypeOf(Response.prototype, GlobalResponse.prototype);
81
82
  Object.defineProperty(global, "Response", {
82
83
  value: Response
83
84
  });
85
+ var stateKey = Reflect.ownKeys(new GlobalResponse()).find(
86
+ (k) => typeof k === "symbol" && k.toString() === "Symbol(state)"
87
+ );
88
+ if (!stateKey) {
89
+ console.warn("Failed to find Response internal state key");
90
+ }
91
+ function getInternalBody(response) {
92
+ if (!stateKey) {
93
+ return;
94
+ }
95
+ if (response instanceof Response) {
96
+ response = response[getResponseCache]();
97
+ }
98
+ const state = response[stateKey];
99
+ return state && state.body || void 0;
100
+ }
84
101
  export {
85
102
  GlobalResponse,
86
103
  Response,
87
- cacheKey
104
+ cacheKey,
105
+ getInternalBody
88
106
  };
@@ -28,8 +28,9 @@ var import_fs = require("fs");
28
28
  // node_modules/hono/dist/utils/filepath.js
29
29
  var getFilePath = (options) => {
30
30
  let filename = options.filename;
31
- if (/(?:^|[\/\\])\.\.(?:$|[\/\\])/.test(filename))
31
+ if (/(?:^|[\/\\])\.\.(?:$|[\/\\])/.test(filename)) {
32
32
  return;
33
+ }
33
34
  let root = options.root || "";
34
35
  const defaultDocument = options.defaultDocument || "index.html";
35
36
  if (filename.endsWith("/")) {
@@ -46,34 +47,27 @@ var getFilePath = (options) => {
46
47
  };
47
48
 
48
49
  // node_modules/hono/dist/utils/mime.js
49
- var getMimeType = (filename) => {
50
+ var getMimeType = (filename, mimes = baseMimes) => {
50
51
  const regexp = /\.([a-zA-Z0-9]+?)$/;
51
52
  const match = filename.match(regexp);
52
- if (!match)
53
+ if (!match) {
53
54
  return;
55
+ }
54
56
  let mimeType = mimes[match[1]];
55
57
  if (mimeType && mimeType.startsWith("text") || mimeType === "application/json") {
56
58
  mimeType += "; charset=utf-8";
57
59
  }
58
60
  return mimeType;
59
61
  };
60
- var mimes = {
62
+ var baseMimes = {
61
63
  aac: "audio/aac",
62
- abw: "application/x-abiword",
63
- arc: "application/x-freearc",
64
64
  avi: "video/x-msvideo",
65
65
  avif: "image/avif",
66
66
  av1: "video/av1",
67
- azw: "application/vnd.amazon.ebook",
68
67
  bin: "application/octet-stream",
69
68
  bmp: "image/bmp",
70
- bz: "application/x-bzip",
71
- bz2: "application/x-bzip2",
72
- csh: "application/x-csh",
73
69
  css: "text/css",
74
70
  csv: "text/csv",
75
- doc: "application/msword",
76
- docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
77
71
  eot: "application/vnd.ms-fontobject",
78
72
  epub: "application/epub+zip",
79
73
  gif: "image/gif",
@@ -82,7 +76,6 @@ var mimes = {
82
76
  html: "text/html",
83
77
  ico: "image/x-icon",
84
78
  ics: "text/calendar",
85
- jar: "application/java-archive",
86
79
  jpeg: "image/jpeg",
87
80
  jpg: "image/jpeg",
88
81
  js: "text/javascript",
@@ -95,31 +88,20 @@ var mimes = {
95
88
  mp3: "audio/mpeg",
96
89
  mp4: "video/mp4",
97
90
  mpeg: "video/mpeg",
98
- mpkg: "application/vnd.apple.installer+xml",
99
- odp: "application/vnd.oasis.opendocument.presentation",
100
- ods: "application/vnd.oasis.opendocument.spreadsheet",
101
- odt: "application/vnd.oasis.opendocument.text",
102
91
  oga: "audio/ogg",
103
92
  ogv: "video/ogg",
104
93
  ogx: "application/ogg",
105
94
  opus: "audio/opus",
106
95
  otf: "font/otf",
107
96
  pdf: "application/pdf",
108
- php: "application/php",
109
97
  png: "image/png",
110
- ppt: "application/vnd.ms-powerpoint",
111
- pptx: "application/vnd.openxmlformats-officedocument.presentationml.presentation",
112
98
  rtf: "application/rtf",
113
- sh: "application/x-sh",
114
99
  svg: "image/svg+xml",
115
- swf: "application/x-shockwave-flash",
116
- tar: "application/x-tar",
117
100
  tif: "image/tiff",
118
101
  tiff: "image/tiff",
119
102
  ts: "video/mp2t",
120
103
  ttf: "font/ttf",
121
104
  txt: "text/plain",
122
- vsd: "application/vnd.visio",
123
105
  wasm: "application/wasm",
124
106
  webm: "video/webm",
125
107
  weba: "audio/webm",
@@ -127,14 +109,10 @@ var mimes = {
127
109
  woff: "font/woff",
128
110
  woff2: "font/woff2",
129
111
  xhtml: "application/xhtml+xml",
130
- xls: "application/vnd.ms-excel",
131
- xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
132
112
  xml: "application/xml",
133
- xul: "application/vnd.mozilla.xul+xml",
134
113
  zip: "application/zip",
135
114
  "3gp": "video/3gpp",
136
115
  "3g2": "video/3gpp2",
137
- "7z": "application/x-7z-compressed",
138
116
  gltf: "model/gltf+json",
139
117
  glb: "model/gltf-binary"
140
118
  };