@wooksjs/event-http 0.7.24 → 0.7.25

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.cjs CHANGED
@@ -198,12 +198,12 @@ async function uncompressBodyStream(encodings, src) {
198
198
 
199
199
  //#endregion
200
200
  //#region packages/event-http/src/compressor/zlib-compressors.ts
201
- const pipeline = node_stream.pipeline;
201
+ const pipeline$1 = node_stream.pipeline;
202
202
  function iterableToReadable(src) {
203
203
  return node_stream.Readable.from(src, { objectMode: false });
204
204
  }
205
205
  function pump(src, transform) {
206
- pipeline(iterableToReadable(src), transform, (err) => {
206
+ pipeline$1(iterableToReadable(src), transform, (err) => {
207
207
  if (err) transform.destroy(err);
208
208
  });
209
209
  return transform;
@@ -1057,46 +1057,41 @@ var HttpResponse = class {
1057
1057
  }
1058
1058
  this._status = defaultStatus[this._req.method] || EHttpStatusCode.OK;
1059
1059
  }
1060
- sendStream(stream$1, method) {
1060
+ sendStream(source, method) {
1061
1061
  this.autoStatus(true);
1062
1062
  this._res.writeHead(this._status, this._headers);
1063
- this._req.once("close", () => {
1064
- stream$1.destroy();
1065
- });
1066
1063
  if (method === "HEAD") {
1067
- stream$1.destroy();
1064
+ source.destroy();
1068
1065
  this._res.end();
1069
1066
  return Promise.resolve();
1070
1067
  }
1071
- return new Promise((resolve, reject) => {
1072
- stream$1.on("error", (e) => {
1073
- this._logger.error("Stream error", e);
1074
- stream$1.destroy();
1075
- this._res.end();
1076
- reject(e);
1077
- });
1078
- stream$1.on("close", () => {
1079
- stream$1.destroy();
1068
+ return this.pipeToResponse(source, "Stream error");
1069
+ }
1070
+ /**
1071
+ * Pipes `source` into the response. `pipeline` destroys the source when the RESPONSE
1072
+ * closes first (the client disconnected — the request's own 'close' fires as soon as its
1073
+ * body is read, so it can't signal that) and destroys the response when the source fails,
1074
+ * so a truncated body never looks complete. A source error is logged, never rethrown:
1075
+ * headers are already sent, and a sync handler's send() is not awaited (an unhandled
1076
+ * rejection would take the process down).
1077
+ */
1078
+ pipeToResponse(source, errorLabel) {
1079
+ return new Promise((resolve) => {
1080
+ (0, stream.pipeline)(source, this._res, (error) => {
1081
+ if (error && error.code !== "ERR_STREAM_PREMATURE_CLOSE") this._logger.error(errorLabel, error);
1080
1082
  resolve();
1081
1083
  });
1082
- stream$1.pipe(this._res);
1083
1084
  });
1084
1085
  }
1085
1086
  async sendFetchResponse(fetchResponse, method) {
1086
1087
  this._status = this._status || fetchResponse.status;
1087
1088
  this.mergeFetchResponseHeaders(fetchResponse);
1088
1089
  this._res.writeHead(this._status, this._headers);
1089
- if (method === "HEAD") {
1090
+ if (method === "HEAD" || !fetchResponse.body) {
1090
1091
  this._res.end();
1091
1092
  return;
1092
1093
  }
1093
- const fetchBody = fetchResponse.body;
1094
- if (fetchBody) try {
1095
- for await (const chunk of fetchBody) this._res.write(chunk);
1096
- } catch (error) {
1097
- this._logger.error("Error streaming fetch response body", error);
1098
- }
1099
- if (!this._res.writableEnded) this._res.end();
1094
+ return this.pipeToResponse(stream.Readable.fromWeb(fetchResponse.body), "Error streaming fetch response body");
1100
1095
  }
1101
1096
  sendRegular(method) {
1102
1097
  const renderedBody = this.renderBody();
@@ -1479,7 +1474,7 @@ function escapeHtml(value) {
1479
1474
  //#endregion
1480
1475
  //#region packages/event-http/src/response/wooks-http-response.ts
1481
1476
  let framework = {
1482
- version: "0.7.24",
1477
+ version: "0.7.25",
1483
1478
  poweredBy: "wooksjs",
1484
1479
  link: "https://wooks.moost.org/",
1485
1480
  image: "https://wooks.moost.org/wooks-full-logo.svg"
package/dist/index.d.ts CHANGED
@@ -450,6 +450,15 @@ declare class HttpResponse {
450
450
  private finalizeCookies;
451
451
  private autoStatus;
452
452
  private sendStream;
453
+ /**
454
+ * Pipes `source` into the response. `pipeline` destroys the source when the RESPONSE
455
+ * closes first (the client disconnected — the request's own 'close' fires as soon as its
456
+ * body is read, so it can't signal that) and destroys the response when the source fails,
457
+ * so a truncated body never looks complete. A source error is logged, never rethrown:
458
+ * headers are already sent, and a sync handler's send() is not awaited (an unhandled
459
+ * rejection would take the process down).
460
+ */
461
+ private pipeToResponse;
453
462
  private sendFetchResponse;
454
463
  private sendRegular;
455
464
  }
package/dist/index.mjs CHANGED
@@ -5,7 +5,7 @@ import { promisify } from "node:util";
5
5
  import { createBrotliCompress, createBrotliDecompress, createDeflate, createGunzip, createGzip, createInflate } from "node:zlib";
6
6
  import { URLSearchParams } from "url";
7
7
  import http, { IncomingMessage, ServerResponse } from "http";
8
- import { Duplex, Readable as Readable$1 } from "stream";
8
+ import { Duplex, Readable as Readable$1, pipeline as pipeline$1 } from "stream";
9
9
  import { WooksAdapterBase } from "wooks";
10
10
  import { Socket } from "net";
11
11
 
@@ -169,12 +169,12 @@ async function uncompressBodyStream(encodings, src) {
169
169
 
170
170
  //#endregion
171
171
  //#region packages/event-http/src/compressor/zlib-compressors.ts
172
- const pipeline$1 = pipeline;
172
+ const pipeline$2 = pipeline;
173
173
  function iterableToReadable(src) {
174
174
  return Readable.from(src, { objectMode: false });
175
175
  }
176
176
  function pump(src, transform) {
177
- pipeline$1(iterableToReadable(src), transform, (err) => {
177
+ pipeline$2(iterableToReadable(src), transform, (err) => {
178
178
  if (err) transform.destroy(err);
179
179
  });
180
180
  return transform;
@@ -1028,46 +1028,41 @@ var HttpResponse = class {
1028
1028
  }
1029
1029
  this._status = defaultStatus[this._req.method] || EHttpStatusCode.OK;
1030
1030
  }
1031
- sendStream(stream, method) {
1031
+ sendStream(source, method) {
1032
1032
  this.autoStatus(true);
1033
1033
  this._res.writeHead(this._status, this._headers);
1034
- this._req.once("close", () => {
1035
- stream.destroy();
1036
- });
1037
1034
  if (method === "HEAD") {
1038
- stream.destroy();
1035
+ source.destroy();
1039
1036
  this._res.end();
1040
1037
  return Promise.resolve();
1041
1038
  }
1042
- return new Promise((resolve, reject) => {
1043
- stream.on("error", (e) => {
1044
- this._logger.error("Stream error", e);
1045
- stream.destroy();
1046
- this._res.end();
1047
- reject(e);
1048
- });
1049
- stream.on("close", () => {
1050
- stream.destroy();
1039
+ return this.pipeToResponse(source, "Stream error");
1040
+ }
1041
+ /**
1042
+ * Pipes `source` into the response. `pipeline` destroys the source when the RESPONSE
1043
+ * closes first (the client disconnected — the request's own 'close' fires as soon as its
1044
+ * body is read, so it can't signal that) and destroys the response when the source fails,
1045
+ * so a truncated body never looks complete. A source error is logged, never rethrown:
1046
+ * headers are already sent, and a sync handler's send() is not awaited (an unhandled
1047
+ * rejection would take the process down).
1048
+ */
1049
+ pipeToResponse(source, errorLabel) {
1050
+ return new Promise((resolve) => {
1051
+ pipeline$1(source, this._res, (error) => {
1052
+ if (error && error.code !== "ERR_STREAM_PREMATURE_CLOSE") this._logger.error(errorLabel, error);
1051
1053
  resolve();
1052
1054
  });
1053
- stream.pipe(this._res);
1054
1055
  });
1055
1056
  }
1056
1057
  async sendFetchResponse(fetchResponse, method) {
1057
1058
  this._status = this._status || fetchResponse.status;
1058
1059
  this.mergeFetchResponseHeaders(fetchResponse);
1059
1060
  this._res.writeHead(this._status, this._headers);
1060
- if (method === "HEAD") {
1061
+ if (method === "HEAD" || !fetchResponse.body) {
1061
1062
  this._res.end();
1062
1063
  return;
1063
1064
  }
1064
- const fetchBody = fetchResponse.body;
1065
- if (fetchBody) try {
1066
- for await (const chunk of fetchBody) this._res.write(chunk);
1067
- } catch (error) {
1068
- this._logger.error("Error streaming fetch response body", error);
1069
- }
1070
- if (!this._res.writableEnded) this._res.end();
1065
+ return this.pipeToResponse(Readable$1.fromWeb(fetchResponse.body), "Error streaming fetch response body");
1071
1066
  }
1072
1067
  sendRegular(method) {
1073
1068
  const renderedBody = this.renderBody();
@@ -1450,7 +1445,7 @@ function escapeHtml(value) {
1450
1445
  //#endregion
1451
1446
  //#region packages/event-http/src/response/wooks-http-response.ts
1452
1447
  let framework = {
1453
- version: "0.7.24",
1448
+ version: "0.7.25",
1454
1449
  poweredBy: "wooksjs",
1455
1450
  link: "https://wooks.moost.org/",
1456
1451
  image: "https://wooks.moost.org/wooks-full-logo.svg"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wooksjs/event-http",
3
- "version": "0.7.24",
3
+ "version": "0.7.25",
4
4
  "description": "@wooksjs/event-http",
5
5
  "keywords": [
6
6
  "api",
@@ -42,14 +42,14 @@
42
42
  "devDependencies": {
43
43
  "typescript": "^5.9.3",
44
44
  "vitest": "^3.2.7",
45
- "@wooksjs/event-core": "^0.7.24",
46
- "wooks": "^0.7.24"
45
+ "@wooksjs/event-core": "^0.7.25",
46
+ "wooks": "^0.7.25"
47
47
  },
48
48
  "peerDependencies": {
49
49
  "@prostojs/logger": "^0.4.3",
50
50
  "@prostojs/router": "^0.3.4",
51
- "@wooksjs/event-core": "^0.7.24",
52
- "wooks": "^0.7.24"
51
+ "@wooksjs/event-core": "^0.7.25",
52
+ "wooks": "^0.7.25"
53
53
  },
54
54
  "scripts": {
55
55
  "build": "rolldown -c ../../rolldown.config.mjs"