@wooksjs/event-http 0.7.5 → 0.7.7

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
@@ -28,9 +28,9 @@ const node_util = __toESM(require("node:util"));
28
28
  const node_zlib = __toESM(require("node:zlib"));
29
29
  const url = __toESM(require("url"));
30
30
  const http = __toESM(require("http"));
31
- const net = __toESM(require("net"));
32
- const wooks = __toESM(require("wooks"));
33
31
  const stream = __toESM(require("stream"));
32
+ const wooks = __toESM(require("wooks"));
33
+ const net = __toESM(require("net"));
34
34
 
35
35
  //#region packages/event-http/src/http-kind.ts
36
36
  /** Event kind definition for HTTP requests. Provides typed context slots for `req`, `response`, and `requestLimits`. */
@@ -945,7 +945,8 @@ var HttpResponse = class {
945
945
  const contentLength = typeof rendered === "string" ? Buffer.byteLength(rendered) : rendered.byteLength;
946
946
  this._headers["content-length"] = contentLength.toString();
947
947
  }
948
- const webResponse = new globalThis.Response(method === "HEAD" ? null : rendered || null, {
948
+ const webBody = method === "HEAD" ? null : rendered instanceof Uint8Array ? rendered.buffer : rendered || null;
949
+ const webResponse = new globalThis.Response(webBody, {
949
950
  status: this._status,
950
951
  headers: this._buildWebHeaders()
951
952
  });
@@ -1448,7 +1449,7 @@ function error_tl_default(ctx) {
1448
1449
  //#endregion
1449
1450
  //#region packages/event-http/src/response/wooks-http-response.ts
1450
1451
  let framework = {
1451
- version: "0.7.4",
1452
+ version: "0.7.6",
1452
1453
  poweredBy: "wooksjs",
1453
1454
  link: "https://wooks.moost.org/",
1454
1455
  image: "https://wooks.moost.org/wooks-full-logo.svg"
@@ -1656,7 +1657,7 @@ var WooksHttp = class extends wooks.WooksAdapterBase {
1656
1657
  * server.listen(3000)
1657
1658
  * ```
1658
1659
  */
1659
- getServerCb() {
1660
+ getServerCb(onNoMatch) {
1660
1661
  const ctxOptions = this.eventContextOptions;
1661
1662
  const RequestLimits = this.opts?.requestLimits;
1662
1663
  const notFoundHandler = this.opts?.onNotFound;
@@ -1672,14 +1673,10 @@ var WooksHttp = class extends wooks.WooksAdapterBase {
1672
1673
  }, () => {
1673
1674
  const ctx = (0, __wooksjs_event_core.current)();
1674
1675
  const handlers = this.wooks.lookupHandlers(method, url$1, ctx);
1675
- if (handlers || notFoundHandler) {
1676
- const result = this.processHandlers(handlers || [notFoundHandler], ctx, response);
1677
- if (result !== null && result !== void 0 && typeof result.then === "function") result.catch((error) => {
1678
- this.logger.error("Internal error, please report", error);
1679
- this.respond(error, response, ctx);
1680
- });
1681
- return result;
1682
- } else {
1676
+ if (handlers) return this.processAndCatch(handlers, ctx, response);
1677
+ else if (onNoMatch) onNoMatch(req, res);
1678
+ else if (notFoundHandler) return this.processAndCatch([notFoundHandler], ctx, response);
1679
+ else {
1683
1680
  this.logger.debug(`404 Not found (${method})${url$1}`);
1684
1681
  const error = new HttpError(404);
1685
1682
  this.respond(error, response, ctx);
@@ -1740,6 +1737,15 @@ var WooksHttp = class extends wooks.WooksAdapterBase {
1740
1737
  }
1741
1738
  }
1742
1739
  }
1740
+ /** Runs handlers and attaches a `.catch()` for async results to avoid unhandled rejections. */
1741
+ processAndCatch(handlers, ctx, response) {
1742
+ const result = this.processHandlers(handlers, ctx, response);
1743
+ if (result !== null && result !== void 0 && typeof result.then === "function") result.catch((error) => {
1744
+ this.logger.error("Internal error, please report", error);
1745
+ this.respond(error, response, ctx);
1746
+ });
1747
+ return result;
1748
+ }
1743
1749
  processHandlers(handlers, ctx, response) {
1744
1750
  for (let i = 0; i < handlers.length; i++) {
1745
1751
  const handler = handlers[i];
@@ -1797,7 +1803,7 @@ var WooksHttp = class extends wooks.WooksAdapterBase {
1797
1803
  * from the calling request unless already present on the given Request.
1798
1804
  *
1799
1805
  * @param request - A Web Standard Request object.
1800
- * @returns A Web Standard Response.
1806
+ * @returns A Web Standard Response, or `null` if no route matched (and no `onNotFound` handler is set).
1801
1807
  */
1802
1808
  async fetch(request) {
1803
1809
  const url$1 = new URL(request.url);
@@ -1810,24 +1816,32 @@ var WooksHttp = class extends wooks.WooksAdapterBase {
1810
1816
  } catch {}
1811
1817
  const fakeReq = createFakeIncomingMessage(request, pathname, callerReq, this.opts?.forwardHeaders);
1812
1818
  const fakeRes = new http.ServerResponse(fakeReq);
1813
- const rawChunks = [];
1814
- const rawHeaders = {};
1819
+ let rawChunks;
1820
+ let rawHeaders;
1815
1821
  let rawStatusCode = 0;
1816
1822
  fakeRes.writeHead = (...args) => {
1817
1823
  rawStatusCode = args[0];
1818
- for (const arg of args) if (typeof arg === "object" && arg !== null) for (const [k, v] of Object.entries(arg)) rawHeaders[k] = v;
1824
+ for (const arg of args) if (typeof arg === "object" && arg !== null) {
1825
+ if (!rawHeaders) rawHeaders = {};
1826
+ for (const [k, v] of Object.entries(arg)) rawHeaders[k] = v;
1827
+ }
1819
1828
  return fakeRes;
1820
1829
  };
1821
- fakeRes.write = (chunk, ...args) => {
1822
- if (chunk !== null && chunk !== void 0) rawChunks.push(typeof chunk === "string" ? buffer.Buffer.from(chunk) : chunk);
1823
- const cb = args.find((a) => typeof a === "function");
1824
- if (cb) cb();
1830
+ fakeRes.write = (chunk, _encoding, cb) => {
1831
+ if (chunk !== null && chunk !== void 0) {
1832
+ if (!rawChunks) rawChunks = [];
1833
+ rawChunks.push(typeof chunk === "string" ? buffer.Buffer.from(chunk) : chunk);
1834
+ }
1835
+ if (typeof cb === "function") cb();
1825
1836
  return true;
1826
1837
  };
1827
- fakeRes.end = (chunk, ...args) => {
1828
- if (chunk !== null && chunk !== void 0 && typeof chunk !== "function") rawChunks.push(typeof chunk === "string" ? buffer.Buffer.from(chunk) : chunk);
1829
- const cb = args.find((a) => typeof a === "function");
1830
- if (cb) cb();
1838
+ fakeRes.end = (chunk, _encoding, cb) => {
1839
+ if (chunk !== null && chunk !== void 0 && typeof chunk !== "function") {
1840
+ if (!rawChunks) rawChunks = [];
1841
+ rawChunks.push(typeof chunk === "string" ? buffer.Buffer.from(chunk) : chunk);
1842
+ }
1843
+ if (typeof chunk === "function") chunk();
1844
+ else if (typeof cb === "function") cb();
1831
1845
  return fakeRes;
1832
1846
  };
1833
1847
  const response = new this.ResponseClass(fakeRes, fakeReq, this.logger, this.opts?.defaultHeaders, true);
@@ -1835,7 +1849,6 @@ var WooksHttp = class extends wooks.WooksAdapterBase {
1835
1849
  if (request.body) bodyBuffer = buffer.Buffer.from(await request.bytes());
1836
1850
  const ctxOptions = this.eventContextOptions;
1837
1851
  const requestLimits = this.opts?.requestLimits;
1838
- const notFoundHandler = this.opts?.onNotFound;
1839
1852
  return createHttpContext(ctxOptions, {
1840
1853
  req: fakeReq,
1841
1854
  response,
@@ -1845,33 +1858,30 @@ var WooksHttp = class extends wooks.WooksAdapterBase {
1845
1858
  if (bodyBuffer) ctx.set(rawBodySlot, Promise.resolve(bodyBuffer));
1846
1859
  try {
1847
1860
  const handlers = this.wooks.lookupHandlers(method, pathname, ctx);
1848
- if (handlers || notFoundHandler) {
1849
- const result = this.processHandlers(handlers || [notFoundHandler], ctx, response);
1861
+ if (handlers) {
1862
+ const result = this.processHandlers(handlers, ctx, response);
1850
1863
  if (result !== null && result !== void 0 && typeof result.then === "function") await result.catch((error) => {
1851
1864
  if (!response.responded) this.respond(error, response, ctx);
1852
1865
  });
1853
- } else {
1854
- const error = new HttpError(404);
1855
- this.respond(error, response, ctx);
1856
- }
1866
+ } else return null;
1857
1867
  } finally {
1858
1868
  fakeReq.emit("end");
1859
1869
  fakeReq.emit("close");
1870
+ fakeReq.destroy();
1871
+ fakeRes.destroy();
1860
1872
  }
1861
1873
  let webResponse;
1862
- if (rawChunks.length > 0 || rawStatusCode > 0) {
1863
- const body = buffer.Buffer.concat(rawChunks);
1864
- webResponse = new Response(body.length > 0 ? body : null, {
1874
+ if (rawChunks || rawStatusCode > 0) {
1875
+ const body = rawChunks ? buffer.Buffer.concat(rawChunks) : null;
1876
+ webResponse = new Response(body && body.length > 0 ? body : null, {
1865
1877
  status: rawStatusCode || 200,
1866
- headers: recordToWebHeaders(rawHeaders)
1878
+ headers: rawHeaders ? recordToWebHeaders(rawHeaders) : void 0
1867
1879
  });
1868
1880
  } else webResponse = response.toWebResponse();
1869
1881
  if (callerReq) try {
1870
1882
  const parentResponse = callerCtx?.get(httpKind.keys.response);
1871
1883
  if (parentResponse) for (const cookie of webResponse.headers.getSetCookie()) parentResponse.setCookieRaw(cookie);
1872
1884
  } catch {}
1873
- fakeReq.destroy();
1874
- fakeRes.destroy();
1875
1885
  return webResponse;
1876
1886
  });
1877
1887
  }
@@ -1890,8 +1900,16 @@ var WooksHttp = class extends wooks.WooksAdapterBase {
1890
1900
  return this.fetch(req);
1891
1901
  }
1892
1902
  };
1903
+ var NoopSocket = class extends stream.Duplex {
1904
+ remoteAddress = "127.0.0.1";
1905
+ _read() {}
1906
+ _write(_chunk, _enc, cb) {
1907
+ cb();
1908
+ }
1909
+ };
1910
+ const NOOP_SOCKET = new NoopSocket();
1893
1911
  function createFakeIncomingMessage(request, pathname, forwardFrom, forwardHeaders) {
1894
- const req = new http.IncomingMessage(new net.Socket({}));
1912
+ const req = new http.IncomingMessage(NOOP_SOCKET);
1895
1913
  req.method = request.method;
1896
1914
  req.url = pathname;
1897
1915
  const headers = {};
@@ -1902,9 +1920,7 @@ function createFakeIncomingMessage(request, pathname, forwardFrom, forwardHeader
1902
1920
  if (typeof val === "string" && val) headers[h] = val;
1903
1921
  }
1904
1922
  }
1905
- request.headers.forEach((value, key) => {
1906
- headers[key] = value;
1907
- });
1923
+ for (const [key, value] of request.headers) headers[key] = value;
1908
1924
  req.headers = headers;
1909
1925
  return req;
1910
1926
  }
package/dist/index.d.ts CHANGED
@@ -603,13 +603,15 @@ declare class WooksHttp extends WooksAdapterBase {
603
603
  * server.listen(3000)
604
604
  * ```
605
605
  */
606
- getServerCb(): (req: IncomingMessage, res: ServerResponse) => void;
606
+ getServerCb(onNoMatch?: (req: IncomingMessage, res: ServerResponse) => void): (req: IncomingMessage, res: ServerResponse) => void;
607
607
  /**
608
608
  * Returns upgrade callback function for the HTTP server's 'upgrade' event.
609
609
  * Creates an HTTP context, seeds it with upgrade data, and routes as method 'UPGRADE'.
610
610
  */
611
611
  getUpgradeCb(): (req: IncomingMessage, socket: Duplex, head: Buffer) => void;
612
612
  protected processUpgradeHandlers(handlers: TWooksHandler[], ctx: EventContext, socket: Duplex): void | Promise<unknown>;
613
+ /** Runs handlers and attaches a `.catch()` for async results to avoid unhandled rejections. */
614
+ private processAndCatch;
613
615
  protected processHandlers(handlers: TWooksHandler[], ctx: EventContext, response: HttpResponse): void | Promise<unknown>;
614
616
  private processAsyncResult;
615
617
  /**
@@ -622,9 +624,9 @@ declare class WooksHttp extends WooksAdapterBase {
622
624
  * from the calling request unless already present on the given Request.
623
625
  *
624
626
  * @param request - A Web Standard Request object.
625
- * @returns A Web Standard Response.
627
+ * @returns A Web Standard Response, or `null` if no route matched (and no `onNotFound` handler is set).
626
628
  */
627
- fetch(request: Request): Promise<Response>;
629
+ fetch(request: Request): Promise<Response | null>;
628
630
  /**
629
631
  * Convenience wrapper for programmatic route invocation.
630
632
  * Accepts a URL string (relative paths auto-prefixed with `http://localhost`),
@@ -634,7 +636,7 @@ declare class WooksHttp extends WooksAdapterBase {
634
636
  * @param init - Optional RequestInit (method, headers, body, etc.).
635
637
  * @returns A Web Standard Response.
636
638
  */
637
- request(input: string | URL | Request, init?: RequestInit): Promise<Response>;
639
+ request(input: string | URL | Request, init?: RequestInit): Promise<Response | null>;
638
640
  }
639
641
  /**
640
642
  * Creates a new WooksHttp application instance.
package/dist/index.mjs CHANGED
@@ -5,9 +5,9 @@ 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 { Socket } from "net";
8
+ import { Duplex, Readable as Readable$1 } from "stream";
9
9
  import { WooksAdapterBase } from "wooks";
10
- import { Readable as Readable$1 } from "stream";
10
+ import { Socket } from "net";
11
11
 
12
12
  //#region packages/event-http/src/http-kind.ts
13
13
  /** Event kind definition for HTTP requests. Provides typed context slots for `req`, `response`, and `requestLimits`. */
@@ -922,7 +922,8 @@ var HttpResponse = class {
922
922
  const contentLength = typeof rendered === "string" ? Buffer.byteLength(rendered) : rendered.byteLength;
923
923
  this._headers["content-length"] = contentLength.toString();
924
924
  }
925
- const webResponse = new globalThis.Response(method === "HEAD" ? null : rendered || null, {
925
+ const webBody = method === "HEAD" ? null : rendered instanceof Uint8Array ? rendered.buffer : rendered || null;
926
+ const webResponse = new globalThis.Response(webBody, {
926
927
  status: this._status,
927
928
  headers: this._buildWebHeaders()
928
929
  });
@@ -1425,7 +1426,7 @@ function error_tl_default(ctx) {
1425
1426
  //#endregion
1426
1427
  //#region packages/event-http/src/response/wooks-http-response.ts
1427
1428
  let framework = {
1428
- version: "0.7.4",
1429
+ version: "0.7.6",
1429
1430
  poweredBy: "wooksjs",
1430
1431
  link: "https://wooks.moost.org/",
1431
1432
  image: "https://wooks.moost.org/wooks-full-logo.svg"
@@ -1633,7 +1634,7 @@ var WooksHttp = class extends WooksAdapterBase {
1633
1634
  * server.listen(3000)
1634
1635
  * ```
1635
1636
  */
1636
- getServerCb() {
1637
+ getServerCb(onNoMatch) {
1637
1638
  const ctxOptions = this.eventContextOptions;
1638
1639
  const RequestLimits = this.opts?.requestLimits;
1639
1640
  const notFoundHandler = this.opts?.onNotFound;
@@ -1649,14 +1650,10 @@ var WooksHttp = class extends WooksAdapterBase {
1649
1650
  }, () => {
1650
1651
  const ctx = current();
1651
1652
  const handlers = this.wooks.lookupHandlers(method, url, ctx);
1652
- if (handlers || notFoundHandler) {
1653
- const result = this.processHandlers(handlers || [notFoundHandler], ctx, response);
1654
- if (result !== null && result !== void 0 && typeof result.then === "function") result.catch((error) => {
1655
- this.logger.error("Internal error, please report", error);
1656
- this.respond(error, response, ctx);
1657
- });
1658
- return result;
1659
- } else {
1653
+ if (handlers) return this.processAndCatch(handlers, ctx, response);
1654
+ else if (onNoMatch) onNoMatch(req, res);
1655
+ else if (notFoundHandler) return this.processAndCatch([notFoundHandler], ctx, response);
1656
+ else {
1660
1657
  this.logger.debug(`404 Not found (${method})${url}`);
1661
1658
  const error = new HttpError(404);
1662
1659
  this.respond(error, response, ctx);
@@ -1717,6 +1714,15 @@ var WooksHttp = class extends WooksAdapterBase {
1717
1714
  }
1718
1715
  }
1719
1716
  }
1717
+ /** Runs handlers and attaches a `.catch()` for async results to avoid unhandled rejections. */
1718
+ processAndCatch(handlers, ctx, response) {
1719
+ const result = this.processHandlers(handlers, ctx, response);
1720
+ if (result !== null && result !== void 0 && typeof result.then === "function") result.catch((error) => {
1721
+ this.logger.error("Internal error, please report", error);
1722
+ this.respond(error, response, ctx);
1723
+ });
1724
+ return result;
1725
+ }
1720
1726
  processHandlers(handlers, ctx, response) {
1721
1727
  for (let i = 0; i < handlers.length; i++) {
1722
1728
  const handler = handlers[i];
@@ -1774,7 +1780,7 @@ var WooksHttp = class extends WooksAdapterBase {
1774
1780
  * from the calling request unless already present on the given Request.
1775
1781
  *
1776
1782
  * @param request - A Web Standard Request object.
1777
- * @returns A Web Standard Response.
1783
+ * @returns A Web Standard Response, or `null` if no route matched (and no `onNotFound` handler is set).
1778
1784
  */
1779
1785
  async fetch(request) {
1780
1786
  const url = new URL(request.url);
@@ -1787,24 +1793,32 @@ var WooksHttp = class extends WooksAdapterBase {
1787
1793
  } catch {}
1788
1794
  const fakeReq = createFakeIncomingMessage(request, pathname, callerReq, this.opts?.forwardHeaders);
1789
1795
  const fakeRes = new ServerResponse(fakeReq);
1790
- const rawChunks = [];
1791
- const rawHeaders = {};
1796
+ let rawChunks;
1797
+ let rawHeaders;
1792
1798
  let rawStatusCode = 0;
1793
1799
  fakeRes.writeHead = (...args) => {
1794
1800
  rawStatusCode = args[0];
1795
- for (const arg of args) if (typeof arg === "object" && arg !== null) for (const [k, v] of Object.entries(arg)) rawHeaders[k] = v;
1801
+ for (const arg of args) if (typeof arg === "object" && arg !== null) {
1802
+ if (!rawHeaders) rawHeaders = {};
1803
+ for (const [k, v] of Object.entries(arg)) rawHeaders[k] = v;
1804
+ }
1796
1805
  return fakeRes;
1797
1806
  };
1798
- fakeRes.write = (chunk, ...args) => {
1799
- if (chunk !== null && chunk !== void 0) rawChunks.push(typeof chunk === "string" ? Buffer$1.from(chunk) : chunk);
1800
- const cb = args.find((a) => typeof a === "function");
1801
- if (cb) cb();
1807
+ fakeRes.write = (chunk, _encoding, cb) => {
1808
+ if (chunk !== null && chunk !== void 0) {
1809
+ if (!rawChunks) rawChunks = [];
1810
+ rawChunks.push(typeof chunk === "string" ? Buffer$1.from(chunk) : chunk);
1811
+ }
1812
+ if (typeof cb === "function") cb();
1802
1813
  return true;
1803
1814
  };
1804
- fakeRes.end = (chunk, ...args) => {
1805
- if (chunk !== null && chunk !== void 0 && typeof chunk !== "function") rawChunks.push(typeof chunk === "string" ? Buffer$1.from(chunk) : chunk);
1806
- const cb = args.find((a) => typeof a === "function");
1807
- if (cb) cb();
1815
+ fakeRes.end = (chunk, _encoding, cb) => {
1816
+ if (chunk !== null && chunk !== void 0 && typeof chunk !== "function") {
1817
+ if (!rawChunks) rawChunks = [];
1818
+ rawChunks.push(typeof chunk === "string" ? Buffer$1.from(chunk) : chunk);
1819
+ }
1820
+ if (typeof chunk === "function") chunk();
1821
+ else if (typeof cb === "function") cb();
1808
1822
  return fakeRes;
1809
1823
  };
1810
1824
  const response = new this.ResponseClass(fakeRes, fakeReq, this.logger, this.opts?.defaultHeaders, true);
@@ -1812,7 +1826,6 @@ var WooksHttp = class extends WooksAdapterBase {
1812
1826
  if (request.body) bodyBuffer = Buffer$1.from(await request.bytes());
1813
1827
  const ctxOptions = this.eventContextOptions;
1814
1828
  const requestLimits = this.opts?.requestLimits;
1815
- const notFoundHandler = this.opts?.onNotFound;
1816
1829
  return createHttpContext(ctxOptions, {
1817
1830
  req: fakeReq,
1818
1831
  response,
@@ -1822,33 +1835,30 @@ var WooksHttp = class extends WooksAdapterBase {
1822
1835
  if (bodyBuffer) ctx.set(rawBodySlot, Promise.resolve(bodyBuffer));
1823
1836
  try {
1824
1837
  const handlers = this.wooks.lookupHandlers(method, pathname, ctx);
1825
- if (handlers || notFoundHandler) {
1826
- const result = this.processHandlers(handlers || [notFoundHandler], ctx, response);
1838
+ if (handlers) {
1839
+ const result = this.processHandlers(handlers, ctx, response);
1827
1840
  if (result !== null && result !== void 0 && typeof result.then === "function") await result.catch((error) => {
1828
1841
  if (!response.responded) this.respond(error, response, ctx);
1829
1842
  });
1830
- } else {
1831
- const error = new HttpError(404);
1832
- this.respond(error, response, ctx);
1833
- }
1843
+ } else return null;
1834
1844
  } finally {
1835
1845
  fakeReq.emit("end");
1836
1846
  fakeReq.emit("close");
1847
+ fakeReq.destroy();
1848
+ fakeRes.destroy();
1837
1849
  }
1838
1850
  let webResponse;
1839
- if (rawChunks.length > 0 || rawStatusCode > 0) {
1840
- const body = Buffer$1.concat(rawChunks);
1841
- webResponse = new Response(body.length > 0 ? body : null, {
1851
+ if (rawChunks || rawStatusCode > 0) {
1852
+ const body = rawChunks ? Buffer$1.concat(rawChunks) : null;
1853
+ webResponse = new Response(body && body.length > 0 ? body : null, {
1842
1854
  status: rawStatusCode || 200,
1843
- headers: recordToWebHeaders(rawHeaders)
1855
+ headers: rawHeaders ? recordToWebHeaders(rawHeaders) : void 0
1844
1856
  });
1845
1857
  } else webResponse = response.toWebResponse();
1846
1858
  if (callerReq) try {
1847
1859
  const parentResponse = callerCtx?.get(httpKind.keys.response);
1848
1860
  if (parentResponse) for (const cookie of webResponse.headers.getSetCookie()) parentResponse.setCookieRaw(cookie);
1849
1861
  } catch {}
1850
- fakeReq.destroy();
1851
- fakeRes.destroy();
1852
1862
  return webResponse;
1853
1863
  });
1854
1864
  }
@@ -1867,8 +1877,16 @@ var WooksHttp = class extends WooksAdapterBase {
1867
1877
  return this.fetch(req);
1868
1878
  }
1869
1879
  };
1880
+ var NoopSocket = class extends Duplex {
1881
+ remoteAddress = "127.0.0.1";
1882
+ _read() {}
1883
+ _write(_chunk, _enc, cb) {
1884
+ cb();
1885
+ }
1886
+ };
1887
+ const NOOP_SOCKET = new NoopSocket();
1870
1888
  function createFakeIncomingMessage(request, pathname, forwardFrom, forwardHeaders) {
1871
- const req = new IncomingMessage(new Socket({}));
1889
+ const req = new IncomingMessage(NOOP_SOCKET);
1872
1890
  req.method = request.method;
1873
1891
  req.url = pathname;
1874
1892
  const headers = {};
@@ -1879,9 +1897,7 @@ function createFakeIncomingMessage(request, pathname, forwardFrom, forwardHeader
1879
1897
  if (typeof val === "string" && val) headers[h] = val;
1880
1898
  }
1881
1899
  }
1882
- request.headers.forEach((value, key) => {
1883
- headers[key] = value;
1884
- });
1900
+ for (const [key, value] of request.headers) headers[key] = value;
1885
1901
  req.headers = headers;
1886
1902
  return req;
1887
1903
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wooksjs/event-http",
3
- "version": "0.7.5",
3
+ "version": "0.7.7",
4
4
  "description": "@wooksjs/event-http",
5
5
  "keywords": [
6
6
  "api",
@@ -47,14 +47,14 @@
47
47
  "devDependencies": {
48
48
  "typescript": "^5.9.3",
49
49
  "vitest": "^3.2.4",
50
- "@wooksjs/event-core": "^0.7.5",
51
- "wooks": "^0.7.5"
50
+ "@wooksjs/event-core": "^0.7.7",
51
+ "wooks": "^0.7.7"
52
52
  },
53
53
  "peerDependencies": {
54
54
  "@prostojs/logger": "^0.4.3",
55
55
  "@prostojs/router": "^0.3.3",
56
- "@wooksjs/event-core": "^0.7.5",
57
- "wooks": "^0.7.5"
56
+ "@wooksjs/event-core": "^0.7.7",
57
+ "wooks": "^0.7.7"
58
58
  },
59
59
  "scripts": {
60
60
  "build": "rolldown -c ../../rolldown.config.mjs",