@hono/node-server 1.7.0 → 1.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +79 -39
- package/dist/index.mjs +79 -39
- package/dist/listener.js +79 -39
- package/dist/listener.mjs +79 -39
- package/dist/request.d.mts +2 -1
- package/dist/request.d.ts +2 -1
- package/dist/request.js +16 -4
- package/dist/request.mjs +15 -4
- package/dist/response.d.mts +9 -2
- package/dist/response.d.ts +9 -2
- package/dist/response.js +27 -8
- package/dist/response.mjs +25 -7
- package/dist/serve-static.js +6 -28
- package/dist/serve-static.mjs +6 -28
- package/dist/server.js +79 -39
- package/dist/server.mjs +79 -39
- package/dist/utils.js +1 -1
- package/dist/utils.mjs +1 -1
- package/dist/vercel.js +79 -39
- package/dist/vercel.mjs +79 -39
- package/package.json +2 -2
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
|
};
|
|
@@ -67,7 +76,8 @@ var requestPrototype = {
|
|
|
67
76
|
"redirect",
|
|
68
77
|
"referrer",
|
|
69
78
|
"referrerPolicy",
|
|
70
|
-
"signal"
|
|
79
|
+
"signal",
|
|
80
|
+
"keepalive"
|
|
71
81
|
].forEach((k) => {
|
|
72
82
|
Object.defineProperty(requestPrototype, k, {
|
|
73
83
|
get() {
|
|
@@ -145,18 +155,19 @@ var buildOutgoingHttpHeaders = (headers) => {
|
|
|
145
155
|
if (cookies.length > 0) {
|
|
146
156
|
res["set-cookie"] = cookies;
|
|
147
157
|
}
|
|
148
|
-
res["content-type"] ??= "text/plain;charset=UTF-8";
|
|
158
|
+
res["content-type"] ??= "text/plain; charset=UTF-8";
|
|
149
159
|
return res;
|
|
150
160
|
};
|
|
151
161
|
|
|
152
162
|
// src/response.ts
|
|
153
163
|
var responseCache = Symbol("responseCache");
|
|
164
|
+
var getResponseCache = Symbol("getResponseCache");
|
|
154
165
|
var cacheKey = Symbol("cache");
|
|
155
166
|
var GlobalResponse = global.Response;
|
|
156
167
|
var Response2 = class _Response {
|
|
157
168
|
#body;
|
|
158
169
|
#init;
|
|
159
|
-
|
|
170
|
+
[getResponseCache]() {
|
|
160
171
|
delete this[cacheKey];
|
|
161
172
|
return this[responseCache] ||= new GlobalResponse(this.#body, this.#init);
|
|
162
173
|
}
|
|
@@ -166,7 +177,7 @@ var Response2 = class _Response {
|
|
|
166
177
|
const cachedGlobalResponse = init[responseCache];
|
|
167
178
|
if (cachedGlobalResponse) {
|
|
168
179
|
this.#init = cachedGlobalResponse;
|
|
169
|
-
this
|
|
180
|
+
this[getResponseCache]();
|
|
170
181
|
return;
|
|
171
182
|
} else {
|
|
172
183
|
this.#init = init.#init;
|
|
@@ -175,7 +186,7 @@ var Response2 = class _Response {
|
|
|
175
186
|
this.#init = init;
|
|
176
187
|
}
|
|
177
188
|
if (typeof body === "string" || body instanceof ReadableStream) {
|
|
178
|
-
let headers = init?.headers || { "content-type": "text/plain;charset=UTF-8" };
|
|
189
|
+
let headers = init?.headers || { "content-type": "text/plain; charset=UTF-8" };
|
|
179
190
|
if (headers instanceof Headers) {
|
|
180
191
|
headers = buildOutgoingHttpHeaders(headers);
|
|
181
192
|
}
|
|
@@ -198,14 +209,14 @@ var Response2 = class _Response {
|
|
|
198
209
|
].forEach((k) => {
|
|
199
210
|
Object.defineProperty(Response2.prototype, k, {
|
|
200
211
|
get() {
|
|
201
|
-
return this
|
|
212
|
+
return this[getResponseCache]()[k];
|
|
202
213
|
}
|
|
203
214
|
});
|
|
204
215
|
});
|
|
205
216
|
["arrayBuffer", "blob", "clone", "formData", "json", "text"].forEach((k) => {
|
|
206
217
|
Object.defineProperty(Response2.prototype, k, {
|
|
207
218
|
value: function() {
|
|
208
|
-
return this
|
|
219
|
+
return this[getResponseCache]()[k]();
|
|
209
220
|
}
|
|
210
221
|
});
|
|
211
222
|
});
|
|
@@ -214,6 +225,22 @@ Object.setPrototypeOf(Response2.prototype, GlobalResponse.prototype);
|
|
|
214
225
|
Object.defineProperty(global, "Response", {
|
|
215
226
|
value: Response2
|
|
216
227
|
});
|
|
228
|
+
var stateKey = Reflect.ownKeys(new GlobalResponse()).find(
|
|
229
|
+
(k) => typeof k === "symbol" && k.toString() === "Symbol(state)"
|
|
230
|
+
);
|
|
231
|
+
if (!stateKey) {
|
|
232
|
+
console.warn("Failed to find Response internal state key");
|
|
233
|
+
}
|
|
234
|
+
function getInternalBody(response) {
|
|
235
|
+
if (!stateKey) {
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
if (response instanceof Response2) {
|
|
239
|
+
response = response[getResponseCache]();
|
|
240
|
+
}
|
|
241
|
+
const state = response[stateKey];
|
|
242
|
+
return state && state.body || void 0;
|
|
243
|
+
}
|
|
217
244
|
|
|
218
245
|
// src/globals.ts
|
|
219
246
|
import crypto from "crypto";
|
|
@@ -279,36 +306,40 @@ var responseViaResponseObject = async (res, outgoing, options = {}) => {
|
|
|
279
306
|
res = await res.catch(handleFetchError);
|
|
280
307
|
}
|
|
281
308
|
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
if (isCached) {
|
|
285
|
-
return responseViaCache(res, outgoing);
|
|
286
|
-
}
|
|
287
|
-
} catch (e) {
|
|
288
|
-
return handleResponseError(e, outgoing);
|
|
309
|
+
if (cacheKey in res) {
|
|
310
|
+
return responseViaCache(res, outgoing);
|
|
289
311
|
}
|
|
290
312
|
const resHeaderRecord = buildOutgoingHttpHeaders(res.headers);
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
313
|
+
const internalBody = getInternalBody(res);
|
|
314
|
+
if (internalBody) {
|
|
315
|
+
if (internalBody.length) {
|
|
316
|
+
resHeaderRecord["content-length"] = internalBody.length;
|
|
317
|
+
}
|
|
318
|
+
outgoing.writeHead(res.status, resHeaderRecord);
|
|
319
|
+
if (typeof internalBody.source === "string" || internalBody.source instanceof Uint8Array) {
|
|
320
|
+
outgoing.end(internalBody.source);
|
|
321
|
+
} else if (internalBody.source instanceof Blob) {
|
|
322
|
+
outgoing.end(new Uint8Array(await internalBody.source.arrayBuffer()));
|
|
323
|
+
} else {
|
|
324
|
+
await writeFromReadableStream(internalBody.stream, outgoing);
|
|
325
|
+
}
|
|
326
|
+
} else if (res.body) {
|
|
327
|
+
const {
|
|
328
|
+
"transfer-encoding": transferEncoding,
|
|
329
|
+
"content-encoding": contentEncoding,
|
|
330
|
+
"content-length": contentLength,
|
|
331
|
+
"x-accel-buffering": accelBuffering,
|
|
332
|
+
"content-type": contentType
|
|
333
|
+
} = resHeaderRecord;
|
|
334
|
+
if (transferEncoding || contentEncoding || contentLength || // nginx buffering variant
|
|
335
|
+
accelBuffering && regBuffer.test(accelBuffering) || !regContentType.test(contentType)) {
|
|
336
|
+
outgoing.writeHead(res.status, resHeaderRecord);
|
|
337
|
+
await writeFromReadableStream(res.body, outgoing);
|
|
338
|
+
} else {
|
|
339
|
+
const buffer = await res.arrayBuffer();
|
|
340
|
+
resHeaderRecord["content-length"] = buffer.byteLength;
|
|
341
|
+
outgoing.writeHead(res.status, resHeaderRecord);
|
|
342
|
+
outgoing.end(new Uint8Array(buffer));
|
|
312
343
|
}
|
|
313
344
|
} else {
|
|
314
345
|
outgoing.writeHead(res.status, resHeaderRecord);
|
|
@@ -319,6 +350,11 @@ var getRequestListener = (fetchCallback, options = {}) => {
|
|
|
319
350
|
return async (incoming, outgoing) => {
|
|
320
351
|
let res;
|
|
321
352
|
const req = newRequest(incoming);
|
|
353
|
+
outgoing.on("close", () => {
|
|
354
|
+
if (incoming.destroyed) {
|
|
355
|
+
req[getAbortController]().abort();
|
|
356
|
+
}
|
|
357
|
+
});
|
|
322
358
|
try {
|
|
323
359
|
res = fetchCallback(req, { incoming, outgoing });
|
|
324
360
|
if (cacheKey in res) {
|
|
@@ -338,7 +374,11 @@ var getRequestListener = (fetchCallback, options = {}) => {
|
|
|
338
374
|
return handleResponseError(e, outgoing);
|
|
339
375
|
}
|
|
340
376
|
}
|
|
341
|
-
|
|
377
|
+
try {
|
|
378
|
+
return responseViaResponseObject(res, outgoing, options);
|
|
379
|
+
} catch (e) {
|
|
380
|
+
return handleResponseError(e, outgoing);
|
|
381
|
+
}
|
|
342
382
|
};
|
|
343
383
|
};
|
|
344
384
|
export {
|
package/dist/request.d.mts
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.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
|
};
|
|
@@ -93,7 +103,8 @@ var requestPrototype = {
|
|
|
93
103
|
"redirect",
|
|
94
104
|
"referrer",
|
|
95
105
|
"referrerPolicy",
|
|
96
|
-
"signal"
|
|
106
|
+
"signal",
|
|
107
|
+
"keepalive"
|
|
97
108
|
].forEach((k) => {
|
|
98
109
|
Object.defineProperty(requestPrototype, k, {
|
|
99
110
|
get() {
|
|
@@ -121,5 +132,6 @@ var newRequest = (incoming) => {
|
|
|
121
132
|
0 && (module.exports = {
|
|
122
133
|
GlobalRequest,
|
|
123
134
|
Request,
|
|
135
|
+
getAbortController,
|
|
124
136
|
newRequest
|
|
125
137
|
});
|
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
|
};
|
|
@@ -67,7 +76,8 @@ var requestPrototype = {
|
|
|
67
76
|
"redirect",
|
|
68
77
|
"referrer",
|
|
69
78
|
"referrerPolicy",
|
|
70
|
-
"signal"
|
|
79
|
+
"signal",
|
|
80
|
+
"keepalive"
|
|
71
81
|
].forEach((k) => {
|
|
72
82
|
Object.defineProperty(requestPrototype, k, {
|
|
73
83
|
get() {
|
|
@@ -94,5 +104,6 @@ var newRequest = (incoming) => {
|
|
|
94
104
|
export {
|
|
95
105
|
GlobalRequest,
|
|
96
106
|
Request,
|
|
107
|
+
getAbortController,
|
|
97
108
|
newRequest
|
|
98
109
|
};
|
package/dist/response.d.mts
CHANGED
|
@@ -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
|
-
|
|
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.d.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
};
|