Compare commits
6
Commits
c865c2a418
...
d9b0fe09d6
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d9b0fe09d6 | ||
|
|
9829253387 | ||
|
|
e565b1d4c9 | ||
|
|
e112819f64 | ||
|
|
f4d29d8ee8 | ||
|
|
69bdc8adec |
No files matched your search
+10
-2
@@ -63,8 +63,8 @@ npm treats versions as semver and semver forbids leading zeros.
|
|||||||
- **`limits.maxWsMessageBytes` and `limits.maxWsQueue`** (#107): per-connection bounds on inbound
|
- **`limits.maxWsMessageBytes` and `limits.maxWsQueue`** (#107): per-connection bounds on inbound
|
||||||
WebSocket messages, in bytes and in unread messages, server-wide on every runtime. `createApp`
|
WebSocket messages, in bytes and in unread messages, server-wide on every runtime. `createApp`
|
||||||
throws a `TypeError` for anything but a positive integer. Node and Bun refuse an oversized message
|
throws a `TypeError` for anything but a positive integer. Node and Bun refuse an oversized message
|
||||||
before buffering it; Bun does so by dropping the connection, so its peer sees `1006` rather than
|
before buffering it; Bun before 1.4 does so by dropping the connection, so its peer sees `1006`
|
||||||
`1009`. Deno and workerd expose no such option, so there the message is received in full and then
|
rather than `1009` (Bun 1.4 and later send `1009`). Deno and workerd expose no such option, so there the message is received in full and then
|
||||||
refused, and its memory is bounded by the platform's own cap. Worst-case buffered inbound memory is
|
refused, and its memory is bounded by the platform's own cap. Worst-case buffered inbound memory is
|
||||||
about `maxConnections × maxWsQueue × maxWsMessageBytes`, ≈ 15.6 GiB at the Node defaults; Deno and
|
about `maxConnections × maxWsQueue × maxWsMessageBytes`, ≈ 15.6 GiB at the Node defaults; Deno and
|
||||||
Bun have no connection cap, so set one at the platform or proxy there.
|
Bun have no connection cap, so set one at the platform or proxy there.
|
||||||
@@ -83,6 +83,14 @@ npm treats versions as semver and semver forbids leading zeros.
|
|||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
- **Mesh (alpha): `HEAD` on a remote `GET` route now works** (#125). The teacup resolved `HEAD` to
|
||||||
|
the remote `GET` and `OPTIONS` advertised `HEAD`, but the request went to the teapot as `HEAD`,
|
||||||
|
which has no `HEAD` plan, so it answered `404`. The teacup now forwards it as a `GET` and drops
|
||||||
|
the body, so it answers like a local route: the `GET`'s status and headers, no body, and a
|
||||||
|
`404`/`500` from the route keeps its status. An explicit remote `HEAD` route still takes
|
||||||
|
precedence. The teapot is unchanged, so a new teacup works against an older teapot during a
|
||||||
|
rolling deploy.
|
||||||
|
|
||||||
- **`static` no longer serves files outside its root through a symlink** (#106). The traversal guard
|
- **`static` no longer serves files outside its root through a symlink** (#106). The traversal guard
|
||||||
compared paths lexically, and the file read then followed symlinks, so `public/leak -> /etc/hosts`
|
compared paths lexically, and the file read then followed symlinks, so `public/leak -> /etc/hosts`
|
||||||
was served. Containment now compares real paths: the requested file, and a directory's
|
was served. Containment now compares real paths: the requested file, and a directory's
|
||||||
|
|||||||
@@ -141,7 +141,7 @@ without growing the runtime dependency tree past `reflect-metadata`:
|
|||||||
- **Real body parsing.** JSON and urlencoded out of the box; `multipart/form-data` file uploads (`@body()` → `{ fields, files }`) via the optional [`busboy`](https://github.com/mscdex/busboy) peer dependency (`npm i busboy`) — a multipart request without it returns a clear `501`. All size-capped (`413`) against DoS.
|
- **Real body parsing.** JSON and urlencoded out of the box; `multipart/form-data` file uploads (`@body()` → `{ fields, files }`) via the optional [`busboy`](https://github.com/mscdex/busboy) peer dependency (`npm i busboy`) — a multipart request without it returns a clear `501`. All size-capped (`413`) against DoS.
|
||||||
- **Errors, your way.** Throw typed errors (`Unauthorized`, `NotFound`, `HttpError(status, msg, body?)`) anywhere; they convert centrally to `4xx`/`5xx`. Render them however you like — HTML, RFC 7807, content-negotiated — with a single `createApp({ onError })` hook that covers every error response.
|
- **Errors, your way.** Throw typed errors (`Unauthorized`, `NotFound`, `HttpError(status, msg, body?)`) anywhere; they convert centrally to `4xx`/`5xx`. Render them however you like — HTML, RFC 7807, content-negotiated — with a single `createApp({ onError })` hook that covers every error response.
|
||||||
- **HTML without a view layer.** `@Html` returns a string, serves a file, or renders one with the built-in `{{ }}` template engine — swap in EJS or handlebars with `createApp({ viewEngine })`. `createApp({ static: true })` serves `./public` with path-traversal guards and no mime dependency.
|
- **HTML without a view layer.** `@Html` returns a string, serves a file, or renders one with the built-in `{{ }}` template engine — swap in EJS or handlebars with `createApp({ viewEngine })`. `createApp({ static: true })` serves `./public` with path-traversal guards and no mime dependency.
|
||||||
- **Resource ceilings, with safe defaults.** `limits` caps body size (`413`), multipart parts, concurrent Node connections (default `1000`; `<= 0` leaves connections unlimited), and the request / headers / keep-alive timeouts — defaulting to `30s` / `10s` / `5s`, tighter than Node's own two-minute default. `maxConcurrentRequests` is opt-in and applies per server or Fetch adapter instance; when set, excess in-flight requests receive `503` and `Retry-After: 1`. It bounds concurrently executing handlers, so a handler that never returns continues to hold its slot; on Node, a client disconnect releases that slot. Long-lived streams and WebSocket upgrades do not hold that request budget. When Node's connection cap is reached, excess sockets are destroyed without an HTTP response. Deno and Bun expose no equivalent active-socket cap, so enforce one at the deployment platform or reverse proxy there. WebSocket connections are bounded too: `maxWsMessageBytes` (default 1 MiB) closes a connection whose message is larger with `1009`, and `maxWsQueue` (default `16`) closes one that has that many unread inbound messages and receives another with `1013`, rather than dropping anything. Both are server-wide and must be positive integers. Node and Bun refuse an oversized message before buffering it (Bun drops the connection, so its peer sees `1006`); Deno and the edge check it after the runtime has received it. Worst case, a server buffers about `maxConnections × maxWsQueue × maxWsMessageBytes` of inbound messages — ≈ 15.6 GiB at the Node defaults.
|
- **Resource ceilings, with safe defaults.** `limits` caps body size (`413`), multipart parts, concurrent Node connections (default `1000`; `<= 0` leaves connections unlimited), and the request / headers / keep-alive timeouts — defaulting to `30s` / `10s` / `5s`, tighter than Node's own two-minute default. `maxConcurrentRequests` is opt-in and applies per server or Fetch adapter instance; when set, excess in-flight requests receive `503` and `Retry-After: 1`. It bounds concurrently executing handlers, so a handler that never returns continues to hold its slot; on Node, a client disconnect releases that slot. Long-lived streams and WebSocket upgrades do not hold that request budget. When Node's connection cap is reached, excess sockets are destroyed without an HTTP response. Deno and Bun expose no equivalent active-socket cap, so enforce one at the deployment platform or reverse proxy there. WebSocket connections are bounded too: `maxWsMessageBytes` (default 1 MiB) closes a connection whose message is larger with `1009`, and `maxWsQueue` (default `16`) closes one that has that many unread inbound messages and receives another with `1013`, rather than dropping anything. Both are server-wide and must be positive integers. Node and Bun refuse an oversized message before buffering it (Bun before 1.4 drops the connection, so its peer sees `1006`; Bun 1.4 and later send `1009`); Deno and the edge check it after the runtime has received it. Worst case, a server buffers about `maxConnections × maxWsQueue × maxWsMessageBytes` of inbound messages — ≈ 15.6 GiB at the Node defaults.
|
||||||
- **Observability without an integration.** Every request carries an id and a trace id through every lifecycle event, each step reports its own duration, and `createApp({ logger })` accepts any logger — the default writes structured JSON. Nothing in core writes to `console`. Metrics and tracing exporters read the same stream from outside core.
|
- **Observability without an integration.** Every request carries an id and a trace id through every lifecycle event, each step reports its own duration, and `createApp({ logger })` accepts any logger — the default writes structured JSON. Nothing in core writes to `console`. Metrics and tracing exporters read the same stream from outside core.
|
||||||
- **Graceful shutdown, with a deadline.** `app.close()` drains in-flight requests and closes live streams and mesh links, then warns and force-closes whatever is still open after 10 seconds — so a stuck handler cannot hold a deploy open forever. Change the number per call with `close({ timeoutMs })` or for the whole app with `createApp({ shutdownTimeoutMs })`. Connection *draining* is Node-only; on Deno and Bun the server `serveDeno()`/`serveBun()` returns carries the same `close({ timeoutMs })`.
|
- **Graceful shutdown, with a deadline.** `app.close()` drains in-flight requests and closes live streams and mesh links, then warns and force-closes whatever is still open after 10 seconds — so a stuck handler cannot hold a deploy open forever. Change the number per call with `close({ timeoutMs })` or for the whole app with `createApp({ shutdownTimeoutMs })`. Connection *draining* is Node-only; on Deno and Bun the server `serveDeno()`/`serveBun()` returns carries the same `close({ timeoutMs })`.
|
||||||
- **Shutdown is an extension point.** A provider that opened a pool closes it in `dispose()`; a plugin registers `onShutdown(...)`; an application that wants neither passes `createApp({ hooks: [{ onShutdown }] })`. All three land in one registry, run in reverse boot order — a `cache` that needs `db` closes first — and are *awaited*, unlike a `bus.on` listener. A failure is logged and the rest still run, because one broken teardown must not leave the process up. Everything happens inside `close()`'s deadline; `createApp({ teardownTimeoutMs })` reserves a slice of it when a connection must get its chance. *Not available on the edge* — workerd has no shutdown to hook.
|
- **Shutdown is an extension point.** A provider that opened a pool closes it in `dispose()`; a plugin registers `onShutdown(...)`; an application that wants neither passes `createApp({ hooks: [{ onShutdown }] })`. All three land in one registry, run in reverse boot order — a `cache` that needs `db` closes first — and are *awaited*, unlike a `bus.on` listener. A failure is logged and the rest still run, because one broken teardown must not leave the process up. Everything happens inside `close()`'s deadline; `createApp({ teardownTimeoutMs })` reserves a slice of it when a connection must get its chance. *Not available on the edge* — workerd has no shutdown to hook.
|
||||||
|
|||||||
Generated
+51
-63
@@ -1747,7 +1747,6 @@
|
|||||||
"integrity": "sha512-bRImsxibie+AM7xjdwcrm/gr5YeacI65kSBNzTufa1Ib5iwziaY/lqMtRh9THq6pbV4e1HP9aI2ZxGUumnmaoQ==",
|
"integrity": "sha512-bRImsxibie+AM7xjdwcrm/gr5YeacI65kSBNzTufa1Ib5iwziaY/lqMtRh9THq6pbV4e1HP9aI2ZxGUumnmaoQ==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"file-type": "21.3.4",
|
"file-type": "21.3.4",
|
||||||
"iterare": "1.2.1",
|
"iterare": "1.2.1",
|
||||||
@@ -1780,7 +1779,6 @@
|
|||||||
"integrity": "sha512-06m63xIRj8+l8uOeh/8LnYupGubkyu4f+bPKIadaSui6vK9KpXgoz7HveT1yOVLcEt0M0oCOEW5EuEXZkEmBBQ==",
|
"integrity": "sha512-06m63xIRj8+l8uOeh/8LnYupGubkyu4f+bPKIadaSui6vK9KpXgoz7HveT1yOVLcEt0M0oCOEW5EuEXZkEmBBQ==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"fast-safe-stringify": "2.1.1",
|
"fast-safe-stringify": "2.1.1",
|
||||||
"iterare": "1.2.1",
|
"iterare": "1.2.1",
|
||||||
@@ -1821,7 +1819,6 @@
|
|||||||
"integrity": "sha512-+F0hV/4yJM+D/Qwyo5XmKMe6YGEb+ssT2jFWrgdFe1obumXCUeC1GNob/kNeXyzAXm7dcxZVUtmcoqaF6z36jA==",
|
"integrity": "sha512-+F0hV/4yJM+D/Qwyo5XmKMe6YGEb+ssT2jFWrgdFe1obumXCUeC1GNob/kNeXyzAXm7dcxZVUtmcoqaF6z36jA==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"cors": "2.8.6",
|
"cors": "2.8.6",
|
||||||
"express": "5.2.1",
|
"express": "5.2.1",
|
||||||
@@ -2569,7 +2566,6 @@
|
|||||||
"integrity": "sha512-CZ4nMxWwgu1HEEFNkeaCptra9QCtkmKdgf3sWh1rl1trIhmxLilgTV4cwcbQ4wemnT4sWQN8CaKOmdYx+g2gMA==",
|
"integrity": "sha512-CZ4nMxWwgu1HEEFNkeaCptra9QCtkmKdgf3sWh1rl1trIhmxLilgTV4cwcbQ4wemnT4sWQN8CaKOmdYx+g2gMA==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@typescript-eslint/scope-manager": "8.65.0",
|
"@typescript-eslint/scope-manager": "8.65.0",
|
||||||
"@typescript-eslint/types": "8.65.0",
|
"@typescript-eslint/types": "8.65.0",
|
||||||
@@ -2808,16 +2804,16 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@vitest/expect": {
|
"node_modules/@vitest/expect": {
|
||||||
"version": "4.1.11",
|
"version": "4.1.12",
|
||||||
"resolved": "https://registry.npmjs.org/@vitest/expect/-/expect-4.1.11.tgz",
|
"resolved": "https://registry.npmjs.org/@vitest/expect/-/expect-4.1.12.tgz",
|
||||||
"integrity": "sha512-VX2x5vNJXET47KAFzwERI+KRMtTTCSWTfSMKsW7JsUsXV4psq++e3DvZpuTDOpHcxytiDs6p2nhVb2tVDiiUYw==",
|
"integrity": "sha512-vFlTt+YEu9WBpNjdGayNmlMVzrWPi1+sv853/7t2FU7hpO5gAFBKHzQmkCq5Xjpr+evegF2994LQT3hF3mRlqQ==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@standard-schema/spec": "^1.1.0",
|
"@standard-schema/spec": "^1.1.0",
|
||||||
"@types/chai": "^5.2.2",
|
"@types/chai": "^5.2.2",
|
||||||
"@vitest/spy": "4.1.11",
|
"@vitest/spy": "4.1.12",
|
||||||
"@vitest/utils": "4.1.11",
|
"@vitest/utils": "4.1.12",
|
||||||
"chai": "^6.2.2",
|
"chai": "^6.2.2",
|
||||||
"tinyrainbow": "^3.1.0"
|
"tinyrainbow": "^3.1.0"
|
||||||
},
|
},
|
||||||
@@ -2826,13 +2822,13 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@vitest/mocker": {
|
"node_modules/@vitest/mocker": {
|
||||||
"version": "4.1.11",
|
"version": "4.1.12",
|
||||||
"resolved": "https://registry.npmjs.org/@vitest/mocker/-/mocker-4.1.11.tgz",
|
"resolved": "https://registry.npmjs.org/@vitest/mocker/-/mocker-4.1.12.tgz",
|
||||||
"integrity": "sha512-2XJVD55d1o5AZous5CCGKS74g/riOj9odEt2bQpCVZeblHyHdnMeFl4jl0XjU21stf4mbjUkew2eXQZt65g5CQ==",
|
"integrity": "sha512-fKShNpKZzupWZuY0z7egydvL0sqW4INEZBEExMBMAa6izlENEVHwoXgdaTCaBZ5fwlr4xf2o1wXC83n9RpO+NA==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@vitest/spy": "4.1.11",
|
"@vitest/spy": "4.1.12",
|
||||||
"estree-walker": "^3.0.3",
|
"estree-walker": "^3.0.3",
|
||||||
"magic-string": "^0.30.21"
|
"magic-string": "^0.30.21"
|
||||||
},
|
},
|
||||||
@@ -2853,9 +2849,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@vitest/pretty-format": {
|
"node_modules/@vitest/pretty-format": {
|
||||||
"version": "4.1.11",
|
"version": "4.1.12",
|
||||||
"resolved": "https://registry.npmjs.org/@vitest/pretty-format/-/pretty-format-4.1.11.tgz",
|
"resolved": "https://registry.npmjs.org/@vitest/pretty-format/-/pretty-format-4.1.12.tgz",
|
||||||
"integrity": "sha512-yiZzPbGTS9Sr/JpFl8zHrcIkAofNbFV6k21vIgQN/cY/oxZeXhJv5sc/MBJ5jFKWmWs+oJHw0UXLZjmf931+Vw==",
|
"integrity": "sha512-XW9O8+Mxx4VpCtkYdMJLZQQwsVryP9wk7cPKDxtXFfwSak6yRh5+2fep/Y0XF/ElBvJHq8bcYdi6aeuai0opZA==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -2866,13 +2862,13 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@vitest/runner": {
|
"node_modules/@vitest/runner": {
|
||||||
"version": "4.1.11",
|
"version": "4.1.12",
|
||||||
"resolved": "https://registry.npmjs.org/@vitest/runner/-/runner-4.1.11.tgz",
|
"resolved": "https://registry.npmjs.org/@vitest/runner/-/runner-4.1.12.tgz",
|
||||||
"integrity": "sha512-LztvUgdwMNJMIkj3hQnnxiC2Xy1zNxq928W/xhjCLaNCzqTZOudjwbQf6v9IntZGPw132i2Lq2rgTRZHD3JHNw==",
|
"integrity": "sha512-NKlVKCr5QnCe8jijdMnmkpHHU+WTqiLFR6G0pHji9uRjXK9xJl1k1nTw6F3pOOj2PDcsDt2GKQMI7wIsaT491w==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@vitest/utils": "4.1.11",
|
"@vitest/utils": "4.1.12",
|
||||||
"pathe": "^2.0.3"
|
"pathe": "^2.0.3"
|
||||||
},
|
},
|
||||||
"funding": {
|
"funding": {
|
||||||
@@ -2880,14 +2876,14 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@vitest/snapshot": {
|
"node_modules/@vitest/snapshot": {
|
||||||
"version": "4.1.11",
|
"version": "4.1.12",
|
||||||
"resolved": "https://registry.npmjs.org/@vitest/snapshot/-/snapshot-4.1.11.tgz",
|
"resolved": "https://registry.npmjs.org/@vitest/snapshot/-/snapshot-4.1.12.tgz",
|
||||||
"integrity": "sha512-pN7ikn1ON7h8ee4gIAp4AzyK+zBtJPzVbqOgu5LCEh4VaJVbPQcgYQYJIMGQPXVeJJq1fnfazis7a5pFNPahog==",
|
"integrity": "sha512-ko1y1Qgb/slzQ9mr+b89Cuqud8WG1TKtsPD8r7ZUBdvVOGt85Af2HwCqHujrhwJq95hs/9RM7fcAPg57o1vlzw==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@vitest/pretty-format": "4.1.11",
|
"@vitest/pretty-format": "4.1.12",
|
||||||
"@vitest/utils": "4.1.11",
|
"@vitest/utils": "4.1.12",
|
||||||
"magic-string": "^0.30.21",
|
"magic-string": "^0.30.21",
|
||||||
"pathe": "^2.0.3"
|
"pathe": "^2.0.3"
|
||||||
},
|
},
|
||||||
@@ -2896,9 +2892,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@vitest/spy": {
|
"node_modules/@vitest/spy": {
|
||||||
"version": "4.1.11",
|
"version": "4.1.12",
|
||||||
"resolved": "https://registry.npmjs.org/@vitest/spy/-/spy-4.1.11.tgz",
|
"resolved": "https://registry.npmjs.org/@vitest/spy/-/spy-4.1.12.tgz",
|
||||||
"integrity": "sha512-apNa/prQy2qCeywhnixOHPRCgGNhvg7T4Dapfl1GahLp/R+uhBm5cPyFoNVyqsNd2h1nJxL6BqqdIjiABL60YA==",
|
"integrity": "sha512-RGq9x4JNGNTZHEJxvN0oSiJjeSCExm0n2gZKKJZHY9cX5AVA6M7VJILBT3ZJ/tJ/0J9uWT7fETV9/btoi//vSg==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"funding": {
|
"funding": {
|
||||||
@@ -2906,13 +2902,13 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@vitest/utils": {
|
"node_modules/@vitest/utils": {
|
||||||
"version": "4.1.11",
|
"version": "4.1.12",
|
||||||
"resolved": "https://registry.npmjs.org/@vitest/utils/-/utils-4.1.11.tgz",
|
"resolved": "https://registry.npmjs.org/@vitest/utils/-/utils-4.1.12.tgz",
|
||||||
"integrity": "sha512-zTCVGpyFsGWBhllOyKlTw/vnr6D9qxsfSDyfbyZmTyjHw5N/VuvzHpHoQjm2ZJzn4RJgx5w4r7V0er69CmLgPQ==",
|
"integrity": "sha512-Q3awXrwOfEV+qc3WmO5ONyE0yO7Q1gQ9/oyHxGLZ/pl7N3NO/ZztqQwKLuwMkV+CA1JYSIeO3gkHnRDIo4AVaA==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@vitest/pretty-format": "4.1.11",
|
"@vitest/pretty-format": "4.1.12",
|
||||||
"convert-source-map": "^2.0.0",
|
"convert-source-map": "^2.0.0",
|
||||||
"tinyrainbow": "^3.1.0"
|
"tinyrainbow": "^3.1.0"
|
||||||
},
|
},
|
||||||
@@ -2957,7 +2953,6 @@
|
|||||||
"integrity": "sha512-xRQbDb9BnwDafYNn6Vwl839DYVjqXYb1XVGtWAZ1kcDc6iwAL4hg3B1dZlRiuENFeO2H53gFG3in621AdERVAg==",
|
"integrity": "sha512-xRQbDb9BnwDafYNn6Vwl839DYVjqXYb1XVGtWAZ1kcDc6iwAL4hg3B1dZlRiuENFeO2H53gFG3in621AdERVAg==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"bin": {
|
"bin": {
|
||||||
"acorn": "bin/acorn"
|
"acorn": "bin/acorn"
|
||||||
},
|
},
|
||||||
@@ -3894,7 +3889,6 @@
|
|||||||
"dev": true,
|
"dev": true,
|
||||||
"hasInstallScript": true,
|
"hasInstallScript": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"bin": {
|
"bin": {
|
||||||
"esbuild": "bin/esbuild"
|
"esbuild": "bin/esbuild"
|
||||||
},
|
},
|
||||||
@@ -3956,7 +3950,6 @@
|
|||||||
"integrity": "sha512-DgZS62aPLXKlnxILS/AYCoRvHaZeXceIzlXPkkGGzJWSow1aEk0lbTlxUSlyjC8jcaKxAdOnTDz+o1JFSBsyjw==",
|
"integrity": "sha512-DgZS62aPLXKlnxILS/AYCoRvHaZeXceIzlXPkkGGzJWSow1aEk0lbTlxUSlyjC8jcaKxAdOnTDz+o1JFSBsyjw==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@eslint-community/eslint-utils": "^4.8.0",
|
"@eslint-community/eslint-utils": "^4.8.0",
|
||||||
"@eslint-community/regexpp": "^4.12.1",
|
"@eslint-community/regexpp": "^4.12.1",
|
||||||
@@ -4291,9 +4284,9 @@
|
|||||||
"license": "BSD-3-Clause"
|
"license": "BSD-3-Clause"
|
||||||
},
|
},
|
||||||
"node_modules/fastify": {
|
"node_modules/fastify": {
|
||||||
"version": "5.12.5",
|
"version": "5.12.7",
|
||||||
"resolved": "https://registry.npmjs.org/fastify/-/fastify-5.12.5.tgz",
|
"resolved": "https://registry.npmjs.org/fastify/-/fastify-5.12.7.tgz",
|
||||||
"integrity": "sha512-OB2k1dlxs5/NAABqeKV2FUHkSD2BbENsCak8yULVcymn3fHIPDVa9TI3SDnJSWYSllZmSYuZXy2gTnsT+Sut1A==",
|
"integrity": "sha512-v4pEPsTRPuqlDIYiQFB+BHjVN4SdHX9u0ABk0ZDUKbbdY1vsNryUd1j4Z+jQEZajvYIVk047Kimva9/AJ79GYw==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
@@ -6026,7 +6019,6 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"nanoid": "^3.3.16",
|
"nanoid": "^3.3.16",
|
||||||
"picocolors": "^1.1.1",
|
"picocolors": "^1.1.1",
|
||||||
@@ -6285,8 +6277,7 @@
|
|||||||
"version": "0.2.2",
|
"version": "0.2.2",
|
||||||
"resolved": "https://registry.npmjs.org/reflect-metadata/-/reflect-metadata-0.2.2.tgz",
|
"resolved": "https://registry.npmjs.org/reflect-metadata/-/reflect-metadata-0.2.2.tgz",
|
||||||
"integrity": "sha512-urBwgfrvVP/eAyXx4hluJivBKzuEbSQs9rKWCrCkbSxNv8mxPcUZKeuoF3Uy4mJl3Lwprp6yy5/39VWigZ4K6Q==",
|
"integrity": "sha512-urBwgfrvVP/eAyXx4hluJivBKzuEbSQs9rKWCrCkbSxNv8mxPcUZKeuoF3Uy4mJl3Lwprp6yy5/39VWigZ4K6Q==",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0"
|
||||||
"peer": true
|
|
||||||
},
|
},
|
||||||
"node_modules/reinterval": {
|
"node_modules/reinterval": {
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
@@ -6431,7 +6422,6 @@
|
|||||||
"integrity": "sha512-dhKf903U/PQZY6boNNtAGdWbG85WAbjT/1xYoZIC7FAY0yWapOBQVsVrDl58W86//e1VpMNBtRV4MaXfdMySFA==",
|
"integrity": "sha512-dhKf903U/PQZY6boNNtAGdWbG85WAbjT/1xYoZIC7FAY0yWapOBQVsVrDl58W86//e1VpMNBtRV4MaXfdMySFA==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"tslib": "^2.1.0"
|
"tslib": "^2.1.0"
|
||||||
}
|
}
|
||||||
@@ -7203,7 +7193,6 @@
|
|||||||
"integrity": "sha512-rw55FUaqOoI7RvlQwLbhO4nSDApnQ4/CykPuiQ/EPvtrX3WA9Ig55jIt9VvbBJbzJuj12ueRu4PMZ2SxPVbihg==",
|
"integrity": "sha512-rw55FUaqOoI7RvlQwLbhO4nSDApnQ4/CykPuiQ/EPvtrX3WA9Ig55jIt9VvbBJbzJuj12ueRu4PMZ2SxPVbihg==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"esbuild": "~0.28.0"
|
"esbuild": "~0.28.0"
|
||||||
},
|
},
|
||||||
@@ -7753,7 +7742,6 @@
|
|||||||
"integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==",
|
"integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"peer": true,
|
|
||||||
"bin": {
|
"bin": {
|
||||||
"tsc": "bin/tsc",
|
"tsc": "bin/tsc",
|
||||||
"tsserver": "bin/tsserver"
|
"tsserver": "bin/tsserver"
|
||||||
@@ -7888,9 +7876,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/vite": {
|
"node_modules/vite": {
|
||||||
"version": "6.4.3",
|
"version": "6.4.5",
|
||||||
"resolved": "https://registry.npmjs.org/vite/-/vite-6.4.3.tgz",
|
"resolved": "https://registry.npmjs.org/vite/-/vite-6.4.5.tgz",
|
||||||
"integrity": "sha512-NTKlcQjlAK7MlQoyb6LgaqHc8sso/pVyUJYWMws3jg21uTJw/LddqIFPcPqP6PzpgbIcZyKI85sFE4HBrQDA8A==",
|
"integrity": "sha512-4enwjFfi4IwtEh0w+jPzpLVOFQiPHmmzPxcHXQOyEur47o6u0jE573DmGpjA+7irXoMLYRZD5ZaFUEneS3abPg==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -8447,19 +8435,19 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/vitest": {
|
"node_modules/vitest": {
|
||||||
"version": "4.1.11",
|
"version": "4.1.12",
|
||||||
"resolved": "https://registry.npmjs.org/vitest/-/vitest-4.1.11.tgz",
|
"resolved": "https://registry.npmjs.org/vitest/-/vitest-4.1.12.tgz",
|
||||||
"integrity": "sha512-fhACrNXUidIbGSBr5FlbuBkO7VWC1ZyLl0DO4CU2DrQoAPxX84Ysxs+HeGQpii5lZWV1Q4gBZTTu49mF+A6Edw==",
|
"integrity": "sha512-5eWdz2yb3ajxWF3C8C4TjkXl7FGm3n2E/VlazALrQHzK7nYMSGFnCZto0bbPNl77AwkOZVLk0YnBAejUu0NiWA==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@vitest/expect": "4.1.11",
|
"@vitest/expect": "4.1.12",
|
||||||
"@vitest/mocker": "4.1.11",
|
"@vitest/mocker": "4.1.12",
|
||||||
"@vitest/pretty-format": "4.1.11",
|
"@vitest/pretty-format": "4.1.12",
|
||||||
"@vitest/runner": "4.1.11",
|
"@vitest/runner": "4.1.12",
|
||||||
"@vitest/snapshot": "4.1.11",
|
"@vitest/snapshot": "4.1.12",
|
||||||
"@vitest/spy": "4.1.11",
|
"@vitest/spy": "4.1.12",
|
||||||
"@vitest/utils": "4.1.11",
|
"@vitest/utils": "4.1.12",
|
||||||
"es-module-lexer": "^2.0.0",
|
"es-module-lexer": "^2.0.0",
|
||||||
"expect-type": "^1.3.0",
|
"expect-type": "^1.3.0",
|
||||||
"magic-string": "^0.30.21",
|
"magic-string": "^0.30.21",
|
||||||
@@ -8487,12 +8475,12 @@
|
|||||||
"@edge-runtime/vm": "*",
|
"@edge-runtime/vm": "*",
|
||||||
"@opentelemetry/api": "^1.9.0",
|
"@opentelemetry/api": "^1.9.0",
|
||||||
"@types/node": "^20.0.0 || ^22.0.0 || >=24.0.0",
|
"@types/node": "^20.0.0 || ^22.0.0 || >=24.0.0",
|
||||||
"@vitest/browser-playwright": "4.1.11",
|
"@vitest/browser-playwright": "4.1.12",
|
||||||
"@vitest/browser-preview": "4.1.11",
|
"@vitest/browser-preview": "4.1.12",
|
||||||
"@vitest/browser-webdriverio": "4.1.11",
|
"@vitest/browser-webdriverio": "^4.1.11",
|
||||||
"@vitest/coverage-istanbul": "4.1.11",
|
"@vitest/coverage-istanbul": "4.1.12",
|
||||||
"@vitest/coverage-v8": "4.1.11",
|
"@vitest/coverage-v8": "4.1.12",
|
||||||
"@vitest/ui": "4.1.11",
|
"@vitest/ui": "4.1.12",
|
||||||
"happy-dom": "*",
|
"happy-dom": "*",
|
||||||
"jsdom": "*",
|
"jsdom": "*",
|
||||||
"vite": "^6.0.0 || ^7.0.0 || ^8.0.0"
|
"vite": "^6.0.0 || ^7.0.0 || ^8.0.0"
|
||||||
|
|||||||
+5
-1
@@ -1064,7 +1064,11 @@ async function spliceRemoteScopes(
|
|||||||
// protocol never declared, so a teapot could come to rely on something we never promised.
|
// protocol never declared, so a teapot could come to rely on something we never promised.
|
||||||
handler: async (req) =>
|
handler: async (req) =>
|
||||||
route.handler({
|
route.handler({
|
||||||
method: req.method,
|
// HEAD reaches a remote GET through the implicit-HEAD fallback, and the teapot looks
|
||||||
|
// its plan up by method, so a forwarded HEAD finds none and answers 404. Send it as the
|
||||||
|
// GET it resolved to; dispatch drops the body for HEAD. Fixed teacup-side (D16) so an
|
||||||
|
// unchanged, older teapot still answers it during a rolling deploy.
|
||||||
|
method: req.method === 'HEAD' && route.method === 'GET' ? 'GET' : req.method,
|
||||||
params: req.params,
|
params: req.params,
|
||||||
query: req.query,
|
query: req.query,
|
||||||
body: req.body,
|
body: req.body,
|
||||||
|
|||||||
+2
-2
@@ -108,8 +108,8 @@ export async function serveBun(app: App, options?: BunServeShortOptions): Promis
|
|||||||
},
|
},
|
||||||
websocket: {
|
websocket: {
|
||||||
// The pre-buffer half of `limits.maxWsMessageBytes`: Bun refuses an oversized frame before
|
// The pre-buffer half of `limits.maxWsMessageBytes`: Bun refuses an oversized frame before
|
||||||
// assembling it. It drops the connection without a close frame, so the peer sees 1006 rather
|
// assembling it. Up to Bun 1.3 it dropped the connection without a close frame, so the peer
|
||||||
// than 1009 — verified on Bun 1.3, and the price of not buffering the message at all.
|
// saw 1006 rather than 1009 — the price of not buffering the message at all. Bun 1.4 sends 1009.
|
||||||
// `app.upgrade` checks the same bound again on the decoded text.
|
// `app.upgrade` checks the same bound again on the decoded text.
|
||||||
maxPayloadLength:
|
maxPayloadLength:
|
||||||
(app as { [WS_MAX_MESSAGE_BYTES]?: number })[WS_MAX_MESSAGE_BYTES] ?? DEFAULT_MAX_WS_MESSAGE_BYTES,
|
(app as { [WS_MAX_MESSAGE_BYTES]?: number })[WS_MAX_MESSAGE_BYTES] ?? DEFAULT_MAX_WS_MESSAGE_BYTES,
|
||||||
|
|||||||
+2
-2
@@ -22,8 +22,8 @@ export interface RequestLimits {
|
|||||||
* a fragmented message counts as a whole. Must be a positive integer, or `createApp` throws.
|
* a fragmented message counts as a whole. Must be a positive integer, or `createApp` throws.
|
||||||
*
|
*
|
||||||
* Node and Bun refuse an oversized frame before buffering it (`ws`'s `maxPayload`, Bun's
|
* Node and Bun refuse an oversized frame before buffering it (`ws`'s `maxPayload`, Bun's
|
||||||
* `maxPayloadLength`). Bun then drops the connection without a close frame, so on Bun the peer
|
* `maxPayloadLength`). Before Bun 1.4, Bun then drops the connection without a close frame, so
|
||||||
* sees `1006` instead of `1009`. Deno and the edge offer no such option: there the runtime
|
* the peer sees `1006` instead of `1009`; Bun 1.4 and later send `1009`. Deno and the edge offer no such option: there the runtime
|
||||||
* receives the whole message first, so its memory is bounded by the platform's own cap, and this
|
* receives the whole message first, so its memory is bounded by the platform's own cap, and this
|
||||||
* limit is checked after receipt — the connection still closes `1009`.
|
* limit is checked after receipt — the connection still closes `1009`.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -82,3 +82,39 @@ test('mesh on Bun: a teapot refuses a bad secret over its control channel', asyn
|
|||||||
tServer.stop(true);
|
tServer.stop(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// CARD-20 (#125, D16): HEAD on a remote GET answers like HEAD on a local one.
|
||||||
|
@Route('/remote')
|
||||||
|
class RemoteHeadCtl {
|
||||||
|
@Get('/x', { export: true })
|
||||||
|
x() {
|
||||||
|
return { a: 1 };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Module({ mountpoint: '/api', controllers: [RemoteHeadCtl] })
|
||||||
|
class RemoteHeadTeapotModule {}
|
||||||
|
@Module({ mountpoint: '/api', controllers: [] })
|
||||||
|
class EmptyTeacupModule {}
|
||||||
|
|
||||||
|
test('mesh on Bun: HEAD on a remote GET answers 200 with the GET headers and no body', async () => {
|
||||||
|
const teapot = createApp({ modules: [RemoteHeadTeapotModule], experimental: true, mesh: { secret: SECRET } });
|
||||||
|
const tServer = await serveBun(teapot, { port: 0 });
|
||||||
|
|
||||||
|
const teacup = createApp({
|
||||||
|
modules: [EmptyTeacupModule],
|
||||||
|
experimental: true,
|
||||||
|
mesh: { teapots: [{ url: controlUrl(tServer.port), secret: SECRET }], reconnect: false },
|
||||||
|
});
|
||||||
|
const cServer = await serveBun(teacup, { port: 0 });
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await fetch(`http://127.0.0.1:${cServer.port}/api/remote/x`, { method: 'HEAD' });
|
||||||
|
expect(res.status).toBe(200);
|
||||||
|
expect(res.headers.get('content-type') ?? '').toContain('application/json');
|
||||||
|
expect(await res.text()).toBe('');
|
||||||
|
} finally {
|
||||||
|
await teacup.close();
|
||||||
|
cServer.stop(true);
|
||||||
|
tServer.stop(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
+8
-6
@@ -101,10 +101,12 @@ function exchange(port: number, path: string, frames: string[], until = 2000) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// #107: Bun refuses an oversized frame natively (`maxPayloadLength`), before buffering it. Its
|
// #107: Bun refuses an oversized frame natively (`maxPayloadLength`), before buffering it. Up to
|
||||||
// uWebSockets core drops the TCP connection without a close frame, so the peer sees `1006`, not
|
// Bun 1.3 its uWebSockets core dropped the TCP connection without a close frame, so the peer saw
|
||||||
// the `1009` Node, Deno and the edge send. Asserted rather than papered over: it is the documented
|
// `1006`; from Bun 1.4 it sends a real `1009`, like Node, Deno and the edge. Asserted per version
|
||||||
// Bun difference, and a Bun upgrade that starts sending 1009 should fail here and be noticed.
|
// rather than papered over, so a further change in either direction fails here and is noticed.
|
||||||
|
const [bunMajor, bunMinor] = Bun.version.split('.').map(Number);
|
||||||
|
const OVERSIZE_CLOSE = bunMajor > 1 || (bunMajor === 1 && bunMinor >= 4) ? 1009 : 1006;
|
||||||
test('serveBun: ws message size and inbound queue limits', async () => {
|
test('serveBun: ws message size and inbound queue limits', async () => {
|
||||||
const app = createApp({ modules: [M], limits: { maxWsMessageBytes: 1024, maxWsQueue: 4 } });
|
const app = createApp({ modules: [M], limits: { maxWsMessageBytes: 1024, maxWsQueue: 4 } });
|
||||||
const server = await serveBun(app, { port: 0 });
|
const server = await serveBun(app, { port: 0 });
|
||||||
@@ -114,7 +116,7 @@ test('serveBun: ws message size and inbound queue limits', async () => {
|
|||||||
expect(atLimit.replies).toEqual([`echo:${'a'.repeat(1024)}`]);
|
expect(atLimit.replies).toEqual([`echo:${'a'.repeat(1024)}`]);
|
||||||
|
|
||||||
const over = await exchange(port, '/rt/echo', ['a'.repeat(1025)]);
|
const over = await exchange(port, '/rt/echo', ['a'.repeat(1025)]);
|
||||||
expect(over.close?.code).toBe(1006);
|
expect(over.close?.code).toBe(OVERSIZE_CLOSE);
|
||||||
|
|
||||||
const full = await exchange(port, '/rt/stall', ['1', '2', '3', '4', '5']);
|
const full = await exchange(port, '/rt/stall', ['1', '2', '3', '4', '5']);
|
||||||
expect(full.close).toEqual({ code: 1013, reason: 'inbound queue full' });
|
expect(full.close).toEqual({ code: 1013, reason: 'inbound queue full' });
|
||||||
@@ -132,7 +134,7 @@ test('serveBun: ws message size default is 1 MiB', async () => {
|
|||||||
expect(atLimit.replies.length).toBe(1);
|
expect(atLimit.replies.length).toBe(1);
|
||||||
|
|
||||||
const over = await exchange(port, '/rt/echo', ['a'.repeat(1_048_577)]);
|
const over = await exchange(port, '/rt/echo', ['a'.repeat(1_048_577)]);
|
||||||
expect(over.close?.code).toBe(1006);
|
expect(over.close?.code).toBe(OVERSIZE_CLOSE);
|
||||||
} finally {
|
} finally {
|
||||||
server.stop(true);
|
server.stop(true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -106,3 +106,39 @@ Deno.test('mesh on Deno: a teapot refuses a bad secret over its control channel'
|
|||||||
await t.server.shutdown();
|
await t.server.shutdown();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// CARD-20 (#125, D16): HEAD on a remote GET answers like HEAD on a local one.
|
||||||
|
@Route('/remote')
|
||||||
|
class RemoteHeadCtl {
|
||||||
|
@Get('/x', { export: true })
|
||||||
|
x() {
|
||||||
|
return { a: 1 };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Module({ mountpoint: '/api', controllers: [RemoteHeadCtl] })
|
||||||
|
class RemoteHeadTeapotModule {}
|
||||||
|
@Module({ mountpoint: '/api', controllers: [] })
|
||||||
|
class EmptyTeacupModule {}
|
||||||
|
|
||||||
|
Deno.test('mesh on Deno: HEAD on a remote GET answers 200 with the GET headers and no body', async () => {
|
||||||
|
const teapot = createApp({ modules: [RemoteHeadTeapotModule], experimental: true, mesh: { secret: SECRET } });
|
||||||
|
const t = await serve(teapot);
|
||||||
|
|
||||||
|
const teacup = createApp({
|
||||||
|
modules: [EmptyTeacupModule],
|
||||||
|
experimental: true,
|
||||||
|
mesh: { teapots: [{ url: controlUrl(t.port), secret: SECRET }], reconnect: false },
|
||||||
|
});
|
||||||
|
const c = await serve(teacup);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await fetch(`http://127.0.0.1:${c.port}/api/remote/x`, { method: 'HEAD' });
|
||||||
|
assertEquals(res.status, 200);
|
||||||
|
assertStringIncludes(res.headers.get('content-type') ?? '', 'application/json');
|
||||||
|
assertEquals(await res.text(), '');
|
||||||
|
} finally {
|
||||||
|
await teacup.close();
|
||||||
|
await c.server.shutdown();
|
||||||
|
await t.server.shutdown();
|
||||||
|
}
|
||||||
|
});
|
||||||
@@ -0,0 +1,152 @@
|
|||||||
|
/**
|
||||||
|
* CARD-20 (#125, D16): `HEAD` on a remote buffered `GET` behaves like `HEAD` on a local one.
|
||||||
|
*
|
||||||
|
* The teacup resolves `HEAD` to the remote `GET` (implicit HEAD) and forwards it to the teapot as a
|
||||||
|
* `GET`, then drops the body. The teapot is unchanged, so an older teapot works too.
|
||||||
|
*/
|
||||||
|
import 'reflect-metadata';
|
||||||
|
import http from 'http';
|
||||||
|
import type { AddressInfo } from 'net';
|
||||||
|
import { describe, it, expect, afterEach } from 'vitest';
|
||||||
|
import { createApp, Route, Get, Head, Module, NotFound, ctx } from '../../src/index';
|
||||||
|
import type { App } from '../../src/app/types';
|
||||||
|
import type { Logger } from '../../src/logger';
|
||||||
|
|
||||||
|
const SECRET = 'head-secret';
|
||||||
|
const quiet: Logger = { debug: () => {}, info: () => {}, warn: () => {}, error: () => {} };
|
||||||
|
|
||||||
|
const seen: string[] = [];
|
||||||
|
|
||||||
|
@Route('/')
|
||||||
|
class RemoteCtl {
|
||||||
|
@Get('/x', { export: true }) x(@ctx() c: { req: { method: string } }) {
|
||||||
|
seen.push(`x ${c.req.method}`);
|
||||||
|
return { a: 1 };
|
||||||
|
}
|
||||||
|
@Get('/missing', { export: true }) missing() {
|
||||||
|
seen.push('missing');
|
||||||
|
throw new NotFound();
|
||||||
|
}
|
||||||
|
@Get('/boom', { export: true }) boom() {
|
||||||
|
seen.push('boom');
|
||||||
|
throw new Error('kaboom');
|
||||||
|
}
|
||||||
|
@Get('/both', { export: true }) bothGet() {
|
||||||
|
seen.push('both GET');
|
||||||
|
return { via: 'get' };
|
||||||
|
}
|
||||||
|
@Head('/both', { export: true }) bothHead(@ctx() c: { req: { method: string } }) {
|
||||||
|
seen.push(`both HEAD as ${c.req.method}`);
|
||||||
|
return { via: 'head' };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Module({ mountpoint: '/api', controllers: [RemoteCtl] })
|
||||||
|
class TeapotModule {}
|
||||||
|
|
||||||
|
@Module({ mountpoint: '/api', controllers: [] })
|
||||||
|
class TeacupModule {}
|
||||||
|
|
||||||
|
const open: App[] = [];
|
||||||
|
afterEach(async () => {
|
||||||
|
while (open.length) await open.pop()!.close();
|
||||||
|
seen.length = 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
async function mesh(): Promise<{ teacup: App; port: number }> {
|
||||||
|
const teapot = createApp({ modules: [TeapotModule], experimental: true, logger: quiet, mesh: { secret: SECRET } });
|
||||||
|
open.push(teapot);
|
||||||
|
const tPort = ((await teapot.listen(0)).address() as AddressInfo).port;
|
||||||
|
const teacup = createApp({
|
||||||
|
modules: [TeacupModule],
|
||||||
|
experimental: true,
|
||||||
|
logger: quiet,
|
||||||
|
mesh: { teapots: [{ url: `ws://127.0.0.1:${tPort}/__mesh__/control`, secret: SECRET }], reconnect: false },
|
||||||
|
});
|
||||||
|
open.unshift(teacup); // closed first
|
||||||
|
const port = ((await teacup.listen(0)).address() as AddressInfo).port;
|
||||||
|
return { teacup, port };
|
||||||
|
}
|
||||||
|
|
||||||
|
function nodeRequest(port: number, method: string, path: string) {
|
||||||
|
return new Promise<{ status: number; headers: http.IncomingHttpHeaders; body: string }>((resolve, reject) => {
|
||||||
|
const req = http.request({ host: '127.0.0.1', port, method, path, agent: false }, (res) => {
|
||||||
|
let body = '';
|
||||||
|
res.setEncoding('utf8');
|
||||||
|
res.on('data', (chunk) => (body += chunk));
|
||||||
|
res.on('end', () => resolve({ status: res.statusCode ?? 0, headers: res.headers, body }));
|
||||||
|
});
|
||||||
|
req.on('error', reject);
|
||||||
|
req.end();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const fetchVia = (app: App, method: string, path: string) =>
|
||||||
|
app.fetch(new Request(`http://mesh.test${path}`, { method }));
|
||||||
|
|
||||||
|
describe('mesh: HEAD on a remote GET route (CARD-20, D16)', () => {
|
||||||
|
it('T1: HEAD via app.fetch answers 200 with the GET headers and no body', async () => {
|
||||||
|
const { teacup } = await mesh();
|
||||||
|
const get = await fetchVia(teacup, 'GET', '/api/x');
|
||||||
|
const head = await fetchVia(teacup, 'HEAD', '/api/x');
|
||||||
|
expect(head.status).toBe(200);
|
||||||
|
expect(head.headers.get('content-type')).toBe(get.headers.get('content-type'));
|
||||||
|
expect(head.headers.get('content-type')).toContain('application/json');
|
||||||
|
expect(await head.text()).toBe('');
|
||||||
|
expect(await get.json()).toEqual({ a: 1 });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('T2: HEAD via the Node listener answers 200 with the GET headers and no body', async () => {
|
||||||
|
const { port } = await mesh();
|
||||||
|
const get = await nodeRequest(port, 'GET', '/api/x');
|
||||||
|
const head = await nodeRequest(port, 'HEAD', '/api/x');
|
||||||
|
expect(head.status).toBe(200);
|
||||||
|
expect(head.headers['content-type']).toBe(get.headers['content-type']);
|
||||||
|
expect(head.body).toBe('');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('OPTIONS still advertises GET, HEAD, OPTIONS', async () => {
|
||||||
|
const { teacup, port } = await mesh();
|
||||||
|
expect((await fetchVia(teacup, 'OPTIONS', '/api/x')).headers.get('allow')).toBe('GET, HEAD, OPTIONS');
|
||||||
|
expect((await nodeRequest(port, 'OPTIONS', '/api/x')).headers.allow).toBe('GET, HEAD, OPTIONS');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('T3: an explicit remote HEAD route keeps precedence over the implicit fallback', async () => {
|
||||||
|
const { teacup, port } = await mesh();
|
||||||
|
const viaFetch = await fetchVia(teacup, 'HEAD', '/api/both');
|
||||||
|
expect(viaFetch.status).toBe(200);
|
||||||
|
expect(await viaFetch.text()).toBe('');
|
||||||
|
const viaNode = await nodeRequest(port, 'HEAD', '/api/both');
|
||||||
|
expect(viaNode.status).toBe(200);
|
||||||
|
expect(viaNode.body).toBe('');
|
||||||
|
// The explicit HEAD handler ran, reached as HEAD — the GET handler never did.
|
||||||
|
expect(seen).toEqual(['both HEAD as HEAD', 'both HEAD as HEAD']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('T4: a remote GET that throws NotFound answers HEAD with 404 and no body', async () => {
|
||||||
|
const { teacup, port } = await mesh();
|
||||||
|
const viaFetch = await fetchVia(teacup, 'HEAD', '/api/missing');
|
||||||
|
expect(viaFetch.status).toBe(404);
|
||||||
|
expect(await viaFetch.text()).toBe('');
|
||||||
|
const viaNode = await nodeRequest(port, 'HEAD', '/api/missing');
|
||||||
|
expect(viaNode.status).toBe(404);
|
||||||
|
expect(viaNode.body).toBe('');
|
||||||
|
// The teapot handler ran: the 404 is the route's, not a missing HEAD plan on the teapot.
|
||||||
|
expect(seen).toEqual(['missing', 'missing']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('a remote GET that fails answers HEAD with 500 and no body', async () => {
|
||||||
|
const { teacup, port } = await mesh();
|
||||||
|
const viaFetch = await fetchVia(teacup, 'HEAD', '/api/boom');
|
||||||
|
expect(viaFetch.status).toBe(500);
|
||||||
|
expect(await viaFetch.text()).toBe('');
|
||||||
|
const viaNode = await nodeRequest(port, 'HEAD', '/api/boom');
|
||||||
|
expect(viaNode.status).toBe(500);
|
||||||
|
expect(viaNode.body).toBe('');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('T5: one HEAD calls the teapot handler once, as a GET', async () => {
|
||||||
|
const { teacup } = await mesh();
|
||||||
|
await fetchVia(teacup, 'HEAD', '/api/x');
|
||||||
|
expect(seen).toEqual(['x GET']);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -206,7 +206,7 @@
|
|||||||
"adapter": "fetch",
|
"adapter": "fetch",
|
||||||
"method": "HEAD",
|
"method": "HEAD",
|
||||||
"path": "/api/x",
|
"path": "/api/x",
|
||||||
"status": 404,
|
"status": 200,
|
||||||
"headers": {
|
"headers": {
|
||||||
"content-type": "application/json",
|
"content-type": "application/json",
|
||||||
"referrer-policy": "no-referrer",
|
"referrer-policy": "no-referrer",
|
||||||
@@ -472,7 +472,7 @@
|
|||||||
"adapter": "node",
|
"adapter": "node",
|
||||||
"method": "HEAD",
|
"method": "HEAD",
|
||||||
"path": "/api/x",
|
"path": "/api/x",
|
||||||
"status": 404,
|
"status": 200,
|
||||||
"headers": {
|
"headers": {
|
||||||
"content-type": "application/json",
|
"content-type": "application/json",
|
||||||
"referrer-policy": "no-referrer",
|
"referrer-policy": "no-referrer",
|
||||||
|
|||||||
@@ -141,9 +141,9 @@ class RemoteMixCtl {
|
|||||||
return { from: 'teapot', route: 'POST /api/v/:id' };
|
return { from: 'teapot', route: 'POST /api/v/:id' };
|
||||||
}
|
}
|
||||||
// Remote only: remote routes are `buffer`, so the teacup's router resolves HEAD to it implicitly.
|
// Remote only: remote routes are `buffer`, so the teacup's router resolves HEAD to it implicitly.
|
||||||
// Captured as observed at ed47836: the teacup forwards the request as HEAD, the teapot looks its
|
// Captured at ed47836 as HEAD → 404 (the teacup forwarded HEAD, and the teapot has no HEAD plan).
|
||||||
// plan up by (pattern, method) and has none for HEAD, so HEAD answers 404 while OPTIONS still
|
// CARD-20 (#125, D16) changed that deliberately, with owner approval: the teacup forwards the
|
||||||
// advertises HEAD. That is the mesh proxy's behaviour, not the matcher's; CARD-07 must keep it.
|
// HEAD as a GET and drops the body, so HEAD now answers 200 like a local route.
|
||||||
@Get('/x', { export: true }) x() {
|
@Get('/x', { export: true }) x() {
|
||||||
return { from: 'teapot', route: 'GET /api/x' };
|
return { from: 'teapot', route: 'GET /api/x' };
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user