@hono/node-server 1.19.9 → 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.
- package/LICENSE +21 -0
- package/README.md +4 -3
- package/dist/index.js +29 -10
- package/dist/index.mjs +29 -10
- package/dist/listener.js +29 -10
- package/dist/listener.mjs +29 -10
- package/dist/response.d.mts +1 -1
- package/dist/response.d.ts +1 -1
- package/dist/response.js +5 -3
- package/dist/response.mjs +5 -3
- package/dist/serve-static.js +15 -1
- package/dist/serve-static.mjs +15 -1
- package/dist/server.js +29 -10
- package/dist/server.mjs +29 -10
- package/dist/vercel.js +29 -10
- package/dist/vercel.mjs +29 -10
- package/package.json +1 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 - present, Yusuke Wada and Hono contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -335,7 +335,7 @@ import { createAdaptorServer } from '@hono/node-server'
|
|
|
335
335
|
|
|
336
336
|
// ...
|
|
337
337
|
|
|
338
|
-
const socketPath ='/tmp/example.sock'
|
|
338
|
+
const socketPath = '/tmp/example.sock'
|
|
339
339
|
|
|
340
340
|
const server = createAdaptorServer(app)
|
|
341
341
|
server.listen(socketPath, () => {
|
|
@@ -348,9 +348,10 @@ server.listen(socketPath, () => {
|
|
|
348
348
|
- Hono - <https://hono.dev>
|
|
349
349
|
- Hono GitHub repository - <https://github.com/honojs/hono>
|
|
350
350
|
|
|
351
|
-
##
|
|
351
|
+
## Authors
|
|
352
352
|
|
|
353
|
-
Yusuke Wada <https://github.com/yusukebe>
|
|
353
|
+
- Yusuke Wada <https://github.com/yusukebe>
|
|
354
|
+
- Taku Amano <https://github.com/usualoma>
|
|
354
355
|
|
|
355
356
|
## License
|
|
356
357
|
|
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
|
-
|
|
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(
|
|
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
|
-
|
|
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 (
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
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
|
-
|
|
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(
|
|
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
|
-
|
|
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 (
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
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
|
-
|
|
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(
|
|
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
|
-
|
|
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 (
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
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
|
-
|
|
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(
|
|
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
|
-
|
|
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 (
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
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/dist/response.d.mts
CHANGED
|
@@ -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.d.ts
CHANGED
|
@@ -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
|
-
|
|
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(
|
|
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
|
-
|
|
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(
|
|
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/serve-static.js
CHANGED
|
@@ -70,6 +70,20 @@ var getStats = (path) => {
|
|
|
70
70
|
}
|
|
71
71
|
return stats;
|
|
72
72
|
};
|
|
73
|
+
var tryDecode = (str, decoder) => {
|
|
74
|
+
try {
|
|
75
|
+
return decoder(str);
|
|
76
|
+
} catch {
|
|
77
|
+
return str.replace(/(?:%[0-9A-Fa-f]{2})+/g, (match) => {
|
|
78
|
+
try {
|
|
79
|
+
return decoder(match);
|
|
80
|
+
} catch {
|
|
81
|
+
return match;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
var tryDecodeURI = (str) => tryDecode(str, decodeURI);
|
|
73
87
|
var serveStatic = (options = { root: "" }) => {
|
|
74
88
|
const root = options.root || "";
|
|
75
89
|
const optionPath = options.path;
|
|
@@ -85,7 +99,7 @@ var serveStatic = (options = { root: "" }) => {
|
|
|
85
99
|
filename = optionPath;
|
|
86
100
|
} else {
|
|
87
101
|
try {
|
|
88
|
-
filename =
|
|
102
|
+
filename = tryDecodeURI(c.req.path);
|
|
89
103
|
if (/(?:^|[\/\\])\.\.(?:$|[\/\\])/.test(filename)) {
|
|
90
104
|
throw new Error();
|
|
91
105
|
}
|
package/dist/serve-static.mjs
CHANGED
|
@@ -46,6 +46,20 @@ var getStats = (path) => {
|
|
|
46
46
|
}
|
|
47
47
|
return stats;
|
|
48
48
|
};
|
|
49
|
+
var tryDecode = (str, decoder) => {
|
|
50
|
+
try {
|
|
51
|
+
return decoder(str);
|
|
52
|
+
} catch {
|
|
53
|
+
return str.replace(/(?:%[0-9A-Fa-f]{2})+/g, (match) => {
|
|
54
|
+
try {
|
|
55
|
+
return decoder(match);
|
|
56
|
+
} catch {
|
|
57
|
+
return match;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
var tryDecodeURI = (str) => tryDecode(str, decodeURI);
|
|
49
63
|
var serveStatic = (options = { root: "" }) => {
|
|
50
64
|
const root = options.root || "";
|
|
51
65
|
const optionPath = options.path;
|
|
@@ -61,7 +75,7 @@ var serveStatic = (options = { root: "" }) => {
|
|
|
61
75
|
filename = optionPath;
|
|
62
76
|
} else {
|
|
63
77
|
try {
|
|
64
|
-
filename =
|
|
78
|
+
filename = tryDecodeURI(c.req.path);
|
|
65
79
|
if (/(?:^|[\/\\])\.\.(?:$|[\/\\])/.test(filename)) {
|
|
66
80
|
throw new Error();
|
|
67
81
|
}
|
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
|
-
|
|
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(
|
|
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
|
-
|
|
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 (
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
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
|
-
|
|
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(
|
|
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
|
-
|
|
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 (
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
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/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
|
-
|
|
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(
|
|
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
|
-
|
|
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 (
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
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
|
-
|
|
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(
|
|
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
|
-
|
|
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 (
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
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) {
|