@hono/node-server 1.14.0 → 1.14.2

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.js CHANGED
@@ -197,6 +197,74 @@ var newRequest = (incoming, defaultHostname) => {
197
197
  return req;
198
198
  };
199
199
 
200
+ // src/response.ts
201
+ var responseCache = Symbol("responseCache");
202
+ var getResponseCache = Symbol("getResponseCache");
203
+ var cacheKey = Symbol("cache");
204
+ var GlobalResponse = global.Response;
205
+ var Response2 = class _Response {
206
+ #body;
207
+ #init;
208
+ [getResponseCache]() {
209
+ delete this[cacheKey];
210
+ return this[responseCache] ||= new GlobalResponse(this.#body, this.#init);
211
+ }
212
+ constructor(body, init) {
213
+ let headers;
214
+ this.#body = body;
215
+ if (init instanceof _Response) {
216
+ const cachedGlobalResponse = init[responseCache];
217
+ if (cachedGlobalResponse) {
218
+ this.#init = cachedGlobalResponse;
219
+ this[getResponseCache]();
220
+ return;
221
+ } else {
222
+ this.#init = init.#init;
223
+ headers = new Headers(init.#init.headers);
224
+ }
225
+ } else {
226
+ this.#init = init;
227
+ }
228
+ if (typeof body === "string" || typeof body?.getReader !== "undefined" || body instanceof Blob || body instanceof Uint8Array) {
229
+ headers ||= init?.headers || { "content-type": "text/plain; charset=UTF-8" };
230
+ this[cacheKey] = [init?.status || 200, body, headers];
231
+ }
232
+ }
233
+ get headers() {
234
+ const cache = this[cacheKey];
235
+ if (cache) {
236
+ if (!(cache[2] instanceof Headers)) {
237
+ cache[2] = new Headers(cache[2]);
238
+ }
239
+ return cache[2];
240
+ }
241
+ return this[getResponseCache]().headers;
242
+ }
243
+ get status() {
244
+ return this[cacheKey]?.[0] ?? this[getResponseCache]().status;
245
+ }
246
+ get ok() {
247
+ const status = this.status;
248
+ return status >= 200 && status < 300;
249
+ }
250
+ };
251
+ ["body", "bodyUsed", "redirected", "statusText", "trailers", "type", "url"].forEach((k) => {
252
+ Object.defineProperty(Response2.prototype, k, {
253
+ get() {
254
+ return this[getResponseCache]()[k];
255
+ }
256
+ });
257
+ });
258
+ ["arrayBuffer", "blob", "clone", "formData", "json", "text"].forEach((k) => {
259
+ Object.defineProperty(Response2.prototype, k, {
260
+ value: function() {
261
+ return this[getResponseCache]()[k]();
262
+ }
263
+ });
264
+ });
265
+ Object.setPrototypeOf(Response2, GlobalResponse);
266
+ Object.setPrototypeOf(Response2.prototype, GlobalResponse.prototype);
267
+
200
268
  // src/utils.ts
201
269
  function writeFromReadableStream(stream, writable) {
202
270
  if (stream.locked) {
@@ -257,86 +325,6 @@ var buildOutgoingHttpHeaders = (headers) => {
257
325
  return res;
258
326
  };
259
327
 
260
- // src/response.ts
261
- var responseCache = Symbol("responseCache");
262
- var getResponseCache = Symbol("getResponseCache");
263
- var cacheKey = Symbol("cache");
264
- var GlobalResponse = global.Response;
265
- var Response2 = class _Response {
266
- #body;
267
- #init;
268
- [getResponseCache]() {
269
- delete this[cacheKey];
270
- return this[responseCache] ||= new GlobalResponse(this.#body, this.#init);
271
- }
272
- constructor(body, init) {
273
- this.#body = body;
274
- if (init instanceof _Response) {
275
- const cachedGlobalResponse = init[responseCache];
276
- if (cachedGlobalResponse) {
277
- this.#init = cachedGlobalResponse;
278
- this[getResponseCache]();
279
- return;
280
- } else {
281
- this.#init = init.#init;
282
- }
283
- } else {
284
- this.#init = init;
285
- }
286
- if (typeof body === "string" || typeof body?.getReader !== "undefined") {
287
- let headers = init?.headers || { "content-type": "text/plain; charset=UTF-8" };
288
- if (headers instanceof Headers) {
289
- headers = buildOutgoingHttpHeaders(headers);
290
- }
291
- ;
292
- this[cacheKey] = [init?.status || 200, body, headers];
293
- }
294
- }
295
- };
296
- [
297
- "body",
298
- "bodyUsed",
299
- "headers",
300
- "ok",
301
- "redirected",
302
- "status",
303
- "statusText",
304
- "trailers",
305
- "type",
306
- "url"
307
- ].forEach((k) => {
308
- Object.defineProperty(Response2.prototype, k, {
309
- get() {
310
- return this[getResponseCache]()[k];
311
- }
312
- });
313
- });
314
- ["arrayBuffer", "blob", "clone", "formData", "json", "text"].forEach((k) => {
315
- Object.defineProperty(Response2.prototype, k, {
316
- value: function() {
317
- return this[getResponseCache]()[k]();
318
- }
319
- });
320
- });
321
- Object.setPrototypeOf(Response2, GlobalResponse);
322
- Object.setPrototypeOf(Response2.prototype, GlobalResponse.prototype);
323
- var stateKey = Reflect.ownKeys(new GlobalResponse()).find(
324
- (k) => typeof k === "symbol" && k.toString() === "Symbol(state)"
325
- );
326
- if (!stateKey) {
327
- console.warn("Failed to find Response internal state key");
328
- }
329
- function getInternalBody(response) {
330
- if (!stateKey) {
331
- return;
332
- }
333
- if (response instanceof Response2) {
334
- response = response[getResponseCache]();
335
- }
336
- const state = response[stateKey];
337
- return state && state.body || void 0;
338
- }
339
-
340
328
  // src/utils/response/constants.ts
341
329
  var X_ALREADY_SENT = "x-hono-already-sent";
342
330
 
@@ -378,14 +366,24 @@ var handleResponseError = (e, outgoing) => {
378
366
  outgoing.destroy(err);
379
367
  }
380
368
  };
381
- var responseViaCache = (res, outgoing) => {
382
- const [status, body, header] = res[cacheKey];
369
+ var responseViaCache = async (res, outgoing) => {
370
+ let [status, body, header] = res[cacheKey];
371
+ if (header instanceof Headers) {
372
+ header = buildOutgoingHttpHeaders(header);
373
+ }
383
374
  if (typeof body === "string") {
384
375
  header["Content-Length"] = Buffer.byteLength(body);
385
- outgoing.writeHead(status, header);
376
+ } else if (body instanceof Uint8Array) {
377
+ header["Content-Length"] = body.byteLength;
378
+ } else if (body instanceof Blob) {
379
+ header["Content-Length"] = body.size;
380
+ }
381
+ outgoing.writeHead(status, header);
382
+ if (typeof body === "string" || body instanceof Uint8Array) {
386
383
  outgoing.end(body);
384
+ } else if (body instanceof Blob) {
385
+ outgoing.end(new Uint8Array(await body.arrayBuffer()));
387
386
  } else {
388
- outgoing.writeHead(status, header);
389
387
  return writeFromReadableStream(body, outgoing)?.catch(
390
388
  (e) => handleResponseError(e, outgoing)
391
389
  );
@@ -411,25 +409,6 @@ var responseViaResponseObject = async (res, outgoing, options = {}) => {
411
409
  return responseViaCache(res, outgoing);
412
410
  }
413
411
  const resHeaderRecord = buildOutgoingHttpHeaders(res.headers);
414
- const internalBody = getInternalBody(res);
415
- if (internalBody) {
416
- const { length, source, stream } = internalBody;
417
- if (source instanceof Uint8Array && source.byteLength !== length) {
418
- } else {
419
- if (length) {
420
- resHeaderRecord["content-length"] = length;
421
- }
422
- outgoing.writeHead(res.status, resHeaderRecord);
423
- if (typeof source === "string" || source instanceof Uint8Array) {
424
- outgoing.end(source);
425
- } else if (source instanceof Blob) {
426
- outgoing.end(new Uint8Array(await source.arrayBuffer()));
427
- } else {
428
- await writeFromReadableStream(stream, outgoing);
429
- }
430
- return;
431
- }
432
- }
433
412
  if (res.body) {
434
413
  const {
435
414
  "transfer-encoding": transferEncoding,
@@ -499,7 +478,7 @@ var getRequestListener = (fetchCallback, options = {}) => {
499
478
  }
500
479
  }
501
480
  try {
502
- return responseViaResponseObject(res, outgoing, options);
481
+ return await responseViaResponseObject(res, outgoing, options);
503
482
  } catch (e) {
504
483
  return handleResponseError(e, outgoing);
505
484
  }
package/dist/server.mjs CHANGED
@@ -162,6 +162,74 @@ var newRequest = (incoming, defaultHostname) => {
162
162
  return req;
163
163
  };
164
164
 
165
+ // src/response.ts
166
+ var responseCache = Symbol("responseCache");
167
+ var getResponseCache = Symbol("getResponseCache");
168
+ var cacheKey = Symbol("cache");
169
+ var GlobalResponse = global.Response;
170
+ var Response2 = class _Response {
171
+ #body;
172
+ #init;
173
+ [getResponseCache]() {
174
+ delete this[cacheKey];
175
+ return this[responseCache] ||= new GlobalResponse(this.#body, this.#init);
176
+ }
177
+ constructor(body, init) {
178
+ let headers;
179
+ this.#body = body;
180
+ if (init instanceof _Response) {
181
+ const cachedGlobalResponse = init[responseCache];
182
+ if (cachedGlobalResponse) {
183
+ this.#init = cachedGlobalResponse;
184
+ this[getResponseCache]();
185
+ return;
186
+ } else {
187
+ this.#init = init.#init;
188
+ headers = new Headers(init.#init.headers);
189
+ }
190
+ } else {
191
+ this.#init = init;
192
+ }
193
+ if (typeof body === "string" || typeof body?.getReader !== "undefined" || body instanceof Blob || body instanceof Uint8Array) {
194
+ headers ||= init?.headers || { "content-type": "text/plain; charset=UTF-8" };
195
+ this[cacheKey] = [init?.status || 200, body, headers];
196
+ }
197
+ }
198
+ get headers() {
199
+ const cache = this[cacheKey];
200
+ if (cache) {
201
+ if (!(cache[2] instanceof Headers)) {
202
+ cache[2] = new Headers(cache[2]);
203
+ }
204
+ return cache[2];
205
+ }
206
+ return this[getResponseCache]().headers;
207
+ }
208
+ get status() {
209
+ return this[cacheKey]?.[0] ?? this[getResponseCache]().status;
210
+ }
211
+ get ok() {
212
+ const status = this.status;
213
+ return status >= 200 && status < 300;
214
+ }
215
+ };
216
+ ["body", "bodyUsed", "redirected", "statusText", "trailers", "type", "url"].forEach((k) => {
217
+ Object.defineProperty(Response2.prototype, k, {
218
+ get() {
219
+ return this[getResponseCache]()[k];
220
+ }
221
+ });
222
+ });
223
+ ["arrayBuffer", "blob", "clone", "formData", "json", "text"].forEach((k) => {
224
+ Object.defineProperty(Response2.prototype, k, {
225
+ value: function() {
226
+ return this[getResponseCache]()[k]();
227
+ }
228
+ });
229
+ });
230
+ Object.setPrototypeOf(Response2, GlobalResponse);
231
+ Object.setPrototypeOf(Response2.prototype, GlobalResponse.prototype);
232
+
165
233
  // src/utils.ts
166
234
  function writeFromReadableStream(stream, writable) {
167
235
  if (stream.locked) {
@@ -222,86 +290,6 @@ var buildOutgoingHttpHeaders = (headers) => {
222
290
  return res;
223
291
  };
224
292
 
225
- // src/response.ts
226
- var responseCache = Symbol("responseCache");
227
- var getResponseCache = Symbol("getResponseCache");
228
- var cacheKey = Symbol("cache");
229
- var GlobalResponse = global.Response;
230
- var Response2 = class _Response {
231
- #body;
232
- #init;
233
- [getResponseCache]() {
234
- delete this[cacheKey];
235
- return this[responseCache] ||= new GlobalResponse(this.#body, this.#init);
236
- }
237
- constructor(body, init) {
238
- this.#body = body;
239
- if (init instanceof _Response) {
240
- const cachedGlobalResponse = init[responseCache];
241
- if (cachedGlobalResponse) {
242
- this.#init = cachedGlobalResponse;
243
- this[getResponseCache]();
244
- return;
245
- } else {
246
- this.#init = init.#init;
247
- }
248
- } else {
249
- this.#init = init;
250
- }
251
- if (typeof body === "string" || typeof body?.getReader !== "undefined") {
252
- let headers = init?.headers || { "content-type": "text/plain; charset=UTF-8" };
253
- if (headers instanceof Headers) {
254
- headers = buildOutgoingHttpHeaders(headers);
255
- }
256
- ;
257
- this[cacheKey] = [init?.status || 200, body, headers];
258
- }
259
- }
260
- };
261
- [
262
- "body",
263
- "bodyUsed",
264
- "headers",
265
- "ok",
266
- "redirected",
267
- "status",
268
- "statusText",
269
- "trailers",
270
- "type",
271
- "url"
272
- ].forEach((k) => {
273
- Object.defineProperty(Response2.prototype, k, {
274
- get() {
275
- return this[getResponseCache]()[k];
276
- }
277
- });
278
- });
279
- ["arrayBuffer", "blob", "clone", "formData", "json", "text"].forEach((k) => {
280
- Object.defineProperty(Response2.prototype, k, {
281
- value: function() {
282
- return this[getResponseCache]()[k]();
283
- }
284
- });
285
- });
286
- Object.setPrototypeOf(Response2, GlobalResponse);
287
- Object.setPrototypeOf(Response2.prototype, GlobalResponse.prototype);
288
- var stateKey = Reflect.ownKeys(new GlobalResponse()).find(
289
- (k) => typeof k === "symbol" && k.toString() === "Symbol(state)"
290
- );
291
- if (!stateKey) {
292
- console.warn("Failed to find Response internal state key");
293
- }
294
- function getInternalBody(response) {
295
- if (!stateKey) {
296
- return;
297
- }
298
- if (response instanceof Response2) {
299
- response = response[getResponseCache]();
300
- }
301
- const state = response[stateKey];
302
- return state && state.body || void 0;
303
- }
304
-
305
293
  // src/utils/response/constants.ts
306
294
  var X_ALREADY_SENT = "x-hono-already-sent";
307
295
 
@@ -343,14 +331,24 @@ var handleResponseError = (e, outgoing) => {
343
331
  outgoing.destroy(err);
344
332
  }
345
333
  };
346
- var responseViaCache = (res, outgoing) => {
347
- const [status, body, header] = res[cacheKey];
334
+ var responseViaCache = async (res, outgoing) => {
335
+ let [status, body, header] = res[cacheKey];
336
+ if (header instanceof Headers) {
337
+ header = buildOutgoingHttpHeaders(header);
338
+ }
348
339
  if (typeof body === "string") {
349
340
  header["Content-Length"] = Buffer.byteLength(body);
350
- outgoing.writeHead(status, header);
341
+ } else if (body instanceof Uint8Array) {
342
+ header["Content-Length"] = body.byteLength;
343
+ } else if (body instanceof Blob) {
344
+ header["Content-Length"] = body.size;
345
+ }
346
+ outgoing.writeHead(status, header);
347
+ if (typeof body === "string" || body instanceof Uint8Array) {
351
348
  outgoing.end(body);
349
+ } else if (body instanceof Blob) {
350
+ outgoing.end(new Uint8Array(await body.arrayBuffer()));
352
351
  } else {
353
- outgoing.writeHead(status, header);
354
352
  return writeFromReadableStream(body, outgoing)?.catch(
355
353
  (e) => handleResponseError(e, outgoing)
356
354
  );
@@ -376,25 +374,6 @@ var responseViaResponseObject = async (res, outgoing, options = {}) => {
376
374
  return responseViaCache(res, outgoing);
377
375
  }
378
376
  const resHeaderRecord = buildOutgoingHttpHeaders(res.headers);
379
- const internalBody = getInternalBody(res);
380
- if (internalBody) {
381
- const { length, source, stream } = internalBody;
382
- if (source instanceof Uint8Array && source.byteLength !== length) {
383
- } else {
384
- if (length) {
385
- resHeaderRecord["content-length"] = length;
386
- }
387
- outgoing.writeHead(res.status, resHeaderRecord);
388
- if (typeof source === "string" || source instanceof Uint8Array) {
389
- outgoing.end(source);
390
- } else if (source instanceof Blob) {
391
- outgoing.end(new Uint8Array(await source.arrayBuffer()));
392
- } else {
393
- await writeFromReadableStream(stream, outgoing);
394
- }
395
- return;
396
- }
397
- }
398
377
  if (res.body) {
399
378
  const {
400
379
  "transfer-encoding": transferEncoding,
@@ -464,7 +443,7 @@ var getRequestListener = (fetchCallback, options = {}) => {
464
443
  }
465
444
  }
466
445
  try {
467
- return responseViaResponseObject(res, outgoing, options);
446
+ return await responseViaResponseObject(res, outgoing, options);
468
447
  } catch (e) {
469
448
  return handleResponseError(e, outgoing);
470
449
  }
package/dist/vercel.js CHANGED
@@ -195,6 +195,74 @@ var newRequest = (incoming, defaultHostname) => {
195
195
  return req;
196
196
  };
197
197
 
198
+ // src/response.ts
199
+ var responseCache = Symbol("responseCache");
200
+ var getResponseCache = Symbol("getResponseCache");
201
+ var cacheKey = Symbol("cache");
202
+ var GlobalResponse = global.Response;
203
+ var Response2 = class _Response {
204
+ #body;
205
+ #init;
206
+ [getResponseCache]() {
207
+ delete this[cacheKey];
208
+ return this[responseCache] ||= new GlobalResponse(this.#body, this.#init);
209
+ }
210
+ constructor(body, init) {
211
+ let headers;
212
+ this.#body = body;
213
+ if (init instanceof _Response) {
214
+ const cachedGlobalResponse = init[responseCache];
215
+ if (cachedGlobalResponse) {
216
+ this.#init = cachedGlobalResponse;
217
+ this[getResponseCache]();
218
+ return;
219
+ } else {
220
+ this.#init = init.#init;
221
+ headers = new Headers(init.#init.headers);
222
+ }
223
+ } else {
224
+ this.#init = init;
225
+ }
226
+ if (typeof body === "string" || typeof body?.getReader !== "undefined" || body instanceof Blob || body instanceof Uint8Array) {
227
+ headers ||= init?.headers || { "content-type": "text/plain; charset=UTF-8" };
228
+ this[cacheKey] = [init?.status || 200, body, headers];
229
+ }
230
+ }
231
+ get headers() {
232
+ const cache = this[cacheKey];
233
+ if (cache) {
234
+ if (!(cache[2] instanceof Headers)) {
235
+ cache[2] = new Headers(cache[2]);
236
+ }
237
+ return cache[2];
238
+ }
239
+ return this[getResponseCache]().headers;
240
+ }
241
+ get status() {
242
+ return this[cacheKey]?.[0] ?? this[getResponseCache]().status;
243
+ }
244
+ get ok() {
245
+ const status = this.status;
246
+ return status >= 200 && status < 300;
247
+ }
248
+ };
249
+ ["body", "bodyUsed", "redirected", "statusText", "trailers", "type", "url"].forEach((k) => {
250
+ Object.defineProperty(Response2.prototype, k, {
251
+ get() {
252
+ return this[getResponseCache]()[k];
253
+ }
254
+ });
255
+ });
256
+ ["arrayBuffer", "blob", "clone", "formData", "json", "text"].forEach((k) => {
257
+ Object.defineProperty(Response2.prototype, k, {
258
+ value: function() {
259
+ return this[getResponseCache]()[k]();
260
+ }
261
+ });
262
+ });
263
+ Object.setPrototypeOf(Response2, GlobalResponse);
264
+ Object.setPrototypeOf(Response2.prototype, GlobalResponse.prototype);
265
+
198
266
  // src/utils.ts
199
267
  function writeFromReadableStream(stream, writable) {
200
268
  if (stream.locked) {
@@ -255,86 +323,6 @@ var buildOutgoingHttpHeaders = (headers) => {
255
323
  return res;
256
324
  };
257
325
 
258
- // src/response.ts
259
- var responseCache = Symbol("responseCache");
260
- var getResponseCache = Symbol("getResponseCache");
261
- var cacheKey = Symbol("cache");
262
- var GlobalResponse = global.Response;
263
- var Response2 = class _Response {
264
- #body;
265
- #init;
266
- [getResponseCache]() {
267
- delete this[cacheKey];
268
- return this[responseCache] ||= new GlobalResponse(this.#body, this.#init);
269
- }
270
- constructor(body, init) {
271
- this.#body = body;
272
- if (init instanceof _Response) {
273
- const cachedGlobalResponse = init[responseCache];
274
- if (cachedGlobalResponse) {
275
- this.#init = cachedGlobalResponse;
276
- this[getResponseCache]();
277
- return;
278
- } else {
279
- this.#init = init.#init;
280
- }
281
- } else {
282
- this.#init = init;
283
- }
284
- if (typeof body === "string" || typeof body?.getReader !== "undefined") {
285
- let headers = init?.headers || { "content-type": "text/plain; charset=UTF-8" };
286
- if (headers instanceof Headers) {
287
- headers = buildOutgoingHttpHeaders(headers);
288
- }
289
- ;
290
- this[cacheKey] = [init?.status || 200, body, headers];
291
- }
292
- }
293
- };
294
- [
295
- "body",
296
- "bodyUsed",
297
- "headers",
298
- "ok",
299
- "redirected",
300
- "status",
301
- "statusText",
302
- "trailers",
303
- "type",
304
- "url"
305
- ].forEach((k) => {
306
- Object.defineProperty(Response2.prototype, k, {
307
- get() {
308
- return this[getResponseCache]()[k];
309
- }
310
- });
311
- });
312
- ["arrayBuffer", "blob", "clone", "formData", "json", "text"].forEach((k) => {
313
- Object.defineProperty(Response2.prototype, k, {
314
- value: function() {
315
- return this[getResponseCache]()[k]();
316
- }
317
- });
318
- });
319
- Object.setPrototypeOf(Response2, GlobalResponse);
320
- Object.setPrototypeOf(Response2.prototype, GlobalResponse.prototype);
321
- var stateKey = Reflect.ownKeys(new GlobalResponse()).find(
322
- (k) => typeof k === "symbol" && k.toString() === "Symbol(state)"
323
- );
324
- if (!stateKey) {
325
- console.warn("Failed to find Response internal state key");
326
- }
327
- function getInternalBody(response) {
328
- if (!stateKey) {
329
- return;
330
- }
331
- if (response instanceof Response2) {
332
- response = response[getResponseCache]();
333
- }
334
- const state = response[stateKey];
335
- return state && state.body || void 0;
336
- }
337
-
338
326
  // src/utils/response/constants.ts
339
327
  var X_ALREADY_SENT = "x-hono-already-sent";
340
328
 
@@ -376,14 +364,24 @@ var handleResponseError = (e, outgoing) => {
376
364
  outgoing.destroy(err);
377
365
  }
378
366
  };
379
- var responseViaCache = (res, outgoing) => {
380
- const [status, body, header] = res[cacheKey];
367
+ var responseViaCache = async (res, outgoing) => {
368
+ let [status, body, header] = res[cacheKey];
369
+ if (header instanceof Headers) {
370
+ header = buildOutgoingHttpHeaders(header);
371
+ }
381
372
  if (typeof body === "string") {
382
373
  header["Content-Length"] = Buffer.byteLength(body);
383
- outgoing.writeHead(status, header);
374
+ } else if (body instanceof Uint8Array) {
375
+ header["Content-Length"] = body.byteLength;
376
+ } else if (body instanceof Blob) {
377
+ header["Content-Length"] = body.size;
378
+ }
379
+ outgoing.writeHead(status, header);
380
+ if (typeof body === "string" || body instanceof Uint8Array) {
384
381
  outgoing.end(body);
382
+ } else if (body instanceof Blob) {
383
+ outgoing.end(new Uint8Array(await body.arrayBuffer()));
385
384
  } else {
386
- outgoing.writeHead(status, header);
387
385
  return writeFromReadableStream(body, outgoing)?.catch(
388
386
  (e) => handleResponseError(e, outgoing)
389
387
  );
@@ -409,25 +407,6 @@ var responseViaResponseObject = async (res, outgoing, options = {}) => {
409
407
  return responseViaCache(res, outgoing);
410
408
  }
411
409
  const resHeaderRecord = buildOutgoingHttpHeaders(res.headers);
412
- const internalBody = getInternalBody(res);
413
- if (internalBody) {
414
- const { length, source, stream } = internalBody;
415
- if (source instanceof Uint8Array && source.byteLength !== length) {
416
- } else {
417
- if (length) {
418
- resHeaderRecord["content-length"] = length;
419
- }
420
- outgoing.writeHead(res.status, resHeaderRecord);
421
- if (typeof source === "string" || source instanceof Uint8Array) {
422
- outgoing.end(source);
423
- } else if (source instanceof Blob) {
424
- outgoing.end(new Uint8Array(await source.arrayBuffer()));
425
- } else {
426
- await writeFromReadableStream(stream, outgoing);
427
- }
428
- return;
429
- }
430
- }
431
410
  if (res.body) {
432
411
  const {
433
412
  "transfer-encoding": transferEncoding,
@@ -497,7 +476,7 @@ var getRequestListener = (fetchCallback, options = {}) => {
497
476
  }
498
477
  }
499
478
  try {
500
- return responseViaResponseObject(res, outgoing, options);
479
+ return await responseViaResponseObject(res, outgoing, options);
501
480
  } catch (e) {
502
481
  return handleResponseError(e, outgoing);
503
482
  }