@wooksjs/event-http 0.7.5 → 0.7.6
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 +10 -11
- package/dist/index.d.ts +4 -4
- package/dist/index.mjs +10 -11
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -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
|
|
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.
|
|
1452
|
+
version: "0.7.5",
|
|
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;
|
|
@@ -1679,7 +1680,8 @@ var WooksHttp = class extends wooks.WooksAdapterBase {
|
|
|
1679
1680
|
this.respond(error, response, ctx);
|
|
1680
1681
|
});
|
|
1681
1682
|
return result;
|
|
1682
|
-
} else
|
|
1683
|
+
} else if (onNoMatch) onNoMatch(req, res);
|
|
1684
|
+
else {
|
|
1683
1685
|
this.logger.debug(`404 Not found (${method})${url$1}`);
|
|
1684
1686
|
const error = new HttpError(404);
|
|
1685
1687
|
this.respond(error, response, ctx);
|
|
@@ -1797,7 +1799,7 @@ var WooksHttp = class extends wooks.WooksAdapterBase {
|
|
|
1797
1799
|
* from the calling request unless already present on the given Request.
|
|
1798
1800
|
*
|
|
1799
1801
|
* @param request - A Web Standard Request object.
|
|
1800
|
-
* @returns A Web Standard Response.
|
|
1802
|
+
* @returns A Web Standard Response, or `null` if no route matched (and no `onNotFound` handler is set).
|
|
1801
1803
|
*/
|
|
1802
1804
|
async fetch(request) {
|
|
1803
1805
|
const url$1 = new URL(request.url);
|
|
@@ -1850,13 +1852,12 @@ var WooksHttp = class extends wooks.WooksAdapterBase {
|
|
|
1850
1852
|
if (result !== null && result !== void 0 && typeof result.then === "function") await result.catch((error) => {
|
|
1851
1853
|
if (!response.responded) this.respond(error, response, ctx);
|
|
1852
1854
|
});
|
|
1853
|
-
} else
|
|
1854
|
-
const error = new HttpError(404);
|
|
1855
|
-
this.respond(error, response, ctx);
|
|
1856
|
-
}
|
|
1855
|
+
} else return null;
|
|
1857
1856
|
} finally {
|
|
1858
1857
|
fakeReq.emit("end");
|
|
1859
1858
|
fakeReq.emit("close");
|
|
1859
|
+
fakeReq.destroy();
|
|
1860
|
+
fakeRes.destroy();
|
|
1860
1861
|
}
|
|
1861
1862
|
let webResponse;
|
|
1862
1863
|
if (rawChunks.length > 0 || rawStatusCode > 0) {
|
|
@@ -1870,8 +1871,6 @@ var WooksHttp = class extends wooks.WooksAdapterBase {
|
|
|
1870
1871
|
const parentResponse = callerCtx?.get(httpKind.keys.response);
|
|
1871
1872
|
if (parentResponse) for (const cookie of webResponse.headers.getSetCookie()) parentResponse.setCookieRaw(cookie);
|
|
1872
1873
|
} catch {}
|
|
1873
|
-
fakeReq.destroy();
|
|
1874
|
-
fakeRes.destroy();
|
|
1875
1874
|
return webResponse;
|
|
1876
1875
|
});
|
|
1877
1876
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -603,7 +603,7 @@ 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'.
|
|
@@ -622,9 +622,9 @@ declare class WooksHttp extends WooksAdapterBase {
|
|
|
622
622
|
* from the calling request unless already present on the given Request.
|
|
623
623
|
*
|
|
624
624
|
* @param request - A Web Standard Request object.
|
|
625
|
-
* @returns A Web Standard Response.
|
|
625
|
+
* @returns A Web Standard Response, or `null` if no route matched (and no `onNotFound` handler is set).
|
|
626
626
|
*/
|
|
627
|
-
fetch(request: Request): Promise<Response>;
|
|
627
|
+
fetch(request: Request): Promise<Response | null>;
|
|
628
628
|
/**
|
|
629
629
|
* Convenience wrapper for programmatic route invocation.
|
|
630
630
|
* Accepts a URL string (relative paths auto-prefixed with `http://localhost`),
|
|
@@ -634,7 +634,7 @@ declare class WooksHttp extends WooksAdapterBase {
|
|
|
634
634
|
* @param init - Optional RequestInit (method, headers, body, etc.).
|
|
635
635
|
* @returns A Web Standard Response.
|
|
636
636
|
*/
|
|
637
|
-
request(input: string | URL | Request, init?: RequestInit): Promise<Response>;
|
|
637
|
+
request(input: string | URL | Request, init?: RequestInit): Promise<Response | null>;
|
|
638
638
|
}
|
|
639
639
|
/**
|
|
640
640
|
* Creates a new WooksHttp application instance.
|
package/dist/index.mjs
CHANGED
|
@@ -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
|
|
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.
|
|
1429
|
+
version: "0.7.5",
|
|
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;
|
|
@@ -1656,7 +1657,8 @@ var WooksHttp = class extends WooksAdapterBase {
|
|
|
1656
1657
|
this.respond(error, response, ctx);
|
|
1657
1658
|
});
|
|
1658
1659
|
return result;
|
|
1659
|
-
} else
|
|
1660
|
+
} else if (onNoMatch) onNoMatch(req, res);
|
|
1661
|
+
else {
|
|
1660
1662
|
this.logger.debug(`404 Not found (${method})${url}`);
|
|
1661
1663
|
const error = new HttpError(404);
|
|
1662
1664
|
this.respond(error, response, ctx);
|
|
@@ -1774,7 +1776,7 @@ var WooksHttp = class extends WooksAdapterBase {
|
|
|
1774
1776
|
* from the calling request unless already present on the given Request.
|
|
1775
1777
|
*
|
|
1776
1778
|
* @param request - A Web Standard Request object.
|
|
1777
|
-
* @returns A Web Standard Response.
|
|
1779
|
+
* @returns A Web Standard Response, or `null` if no route matched (and no `onNotFound` handler is set).
|
|
1778
1780
|
*/
|
|
1779
1781
|
async fetch(request) {
|
|
1780
1782
|
const url = new URL(request.url);
|
|
@@ -1827,13 +1829,12 @@ var WooksHttp = class extends WooksAdapterBase {
|
|
|
1827
1829
|
if (result !== null && result !== void 0 && typeof result.then === "function") await result.catch((error) => {
|
|
1828
1830
|
if (!response.responded) this.respond(error, response, ctx);
|
|
1829
1831
|
});
|
|
1830
|
-
} else
|
|
1831
|
-
const error = new HttpError(404);
|
|
1832
|
-
this.respond(error, response, ctx);
|
|
1833
|
-
}
|
|
1832
|
+
} else return null;
|
|
1834
1833
|
} finally {
|
|
1835
1834
|
fakeReq.emit("end");
|
|
1836
1835
|
fakeReq.emit("close");
|
|
1836
|
+
fakeReq.destroy();
|
|
1837
|
+
fakeRes.destroy();
|
|
1837
1838
|
}
|
|
1838
1839
|
let webResponse;
|
|
1839
1840
|
if (rawChunks.length > 0 || rawStatusCode > 0) {
|
|
@@ -1847,8 +1848,6 @@ var WooksHttp = class extends WooksAdapterBase {
|
|
|
1847
1848
|
const parentResponse = callerCtx?.get(httpKind.keys.response);
|
|
1848
1849
|
if (parentResponse) for (const cookie of webResponse.headers.getSetCookie()) parentResponse.setCookieRaw(cookie);
|
|
1849
1850
|
} catch {}
|
|
1850
|
-
fakeReq.destroy();
|
|
1851
|
-
fakeRes.destroy();
|
|
1852
1851
|
return webResponse;
|
|
1853
1852
|
});
|
|
1854
1853
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wooksjs/event-http",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.6",
|
|
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.
|
|
51
|
-
"wooks": "^0.7.
|
|
50
|
+
"@wooksjs/event-core": "^0.7.6",
|
|
51
|
+
"wooks": "^0.7.6"
|
|
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.
|
|
57
|
-
"wooks": "^0.7.
|
|
56
|
+
"@wooksjs/event-core": "^0.7.6",
|
|
57
|
+
"wooks": "^0.7.6"
|
|
58
58
|
},
|
|
59
59
|
"scripts": {
|
|
60
60
|
"build": "rolldown -c ../../rolldown.config.mjs",
|