Skip to content

Commit 9822b05

Browse files
fix(hono): on a createHonoApp host a HEAD is answered as its GET, so HEAD /api/v1/mcp/skill no longer answers 405 Allow: GET (#24286)
Fixes #24245 Clause-②: no Basis for the Clause-② line: the fix removes a refusal the published HTTP contract already rules out. `IHttpServer`'s unmatched-request contract names `@objectstack/http-conformance` as its validator, and that suite pins "answers HEAD from GET routes without a body" (`packages/qa/http-conformance/src/adapter.test.ts:144`), as RFC 9110 §9.3.2 does. No export moves. Every request whose answer changes is a `HEAD` on a `createHonoApp` host, and it now gets its `GET` answer's status and headers with no body. No `GET` answer moved (measured, below). ## What changed - `packages/adapters/hono/src/index.ts` (the home): a module-private `dispatchedMethod(method)` maps `HEAD` to `GET` and leaves every other verb as sent. - The `${prefix}/*` catch-all hands `dispatch()` `dispatchedMethod(method)`. Before, it handed the raw `c.req.method`, which reads `HEAD` even though Hono routed the request as `GET`. - The auth arm's `/auth/config` branch compares `dispatchedMethod(method)`. A `HEAD` there was forwarded to better-auth and answered `404`, while `plugin-auth`'s `GET` mount answers it on the standalone server. This is the same defect class in the same file, and it is fixed under the bounded in-place exemption (same class, mechanical, file in this claim's surface, same gate family). - Only the verb moves. `{ request: c.req.raw }` is still the client's `HEAD` request, as the standalone mounts hand theirs. Hono drops the body itself. - `packages/runtime/src/domains/approvals.ts`: the `/approvals/act` domain decides "is this a `HEAD`" from the forwarded request's own method (`request?.method === 'HEAD'`), not from the dispatcher's verb. This edit is required by the change above. Without it, the hosted `HEAD` reached the approvals member as the raw `HEAD` and answered `405` with `Allow: GET, POST`. Measured: `hono-approvals-act.conformance.test.ts`'s HEAD pin went red with only the catch-all change, because the hosted door answered `405` where the self-hosted door answered `200`. The docblocks that said the two methods are always equal now say where they differ. - Tests and a changeset (`@objectstack/hono` patch, `@objectstack/runtime` patch). ## Where the fix lives, and why (measured) Measured in process on base `53ef75243`, with a `LiteKernel`, fake `auth` / `mcp` / `analytics` / `protocol` slots, and both doors: - the hosted door: `createHonoApp` driven through `app.request`, with `HttpDispatcher.prototype.dispatch` wrapped to record the verb it received and its answer; - the standalone door: `HonoServerPlugin` on a real socket with `createDispatcherPlugin`. The run covered 34 paths × `GET`/`HEAD` × anonymous/signed in. - **A1 (confirmed).** `handleMcpSkillRequest` answers `405` + `Allow: GET` for every method that is not `GET` (`packages/runtime/src/domains/mcp.ts`, the `method !== 'GET'` branch). - **A2 (confirmed).** On the hosted door, `dispatch()` received `HEAD` on every `HEAD` row. - **A3 (confirmed).** The standalone door answered every `HEAD` row exactly as its `GET` row. Its transport routes a `HEAD` to the `GET` mount, and the mount hands `dispatch()` a literal `'GET'`. - **A4 (answered: Hono drops it).** `hono` 4.13.12 `hono-base` re-dispatches a `HEAD` as `GET` and wraps the answer in `new Response(null, …)`. Every `HEAD` answer through `app.request` had an empty body, at base and at head. **Why the catch-all and not the `mcp` domain.** The shape is not the `mcp` domain's. The dispatcher decides a verb by comparing it with `'GET'` in many places: a domain's `methods` filter (`/health`, `/ready`), a domain's branches (`m === 'GET'`), the discovery root, and the share-link floor's public-`GET` exemption. Through the hosted door, 13 of 68 `HEAD` rows answered differently from their `GET`, across 7 route families (table below). A domain-level `HEAD`-as-`GET` would close one of them and leave a dialect to repeat in every other domain. The catch-all is the one producer of the raw `HEAD` on this host. Mapping it there gives both compositions the same `dispatch()` input: the verb `GET`, beside a request whose method is `HEAD`. **The PM's two checks:** - A path that serves no `GET` keeps its `GET` answer for `HEAD`. For `/keys` and `/actions/task/close`, signed in, that is `405` + `Allow: POST`; anonymous, `401 UNAUTHENTICATED`. These answers are unchanged from base, on both doors. A `HEAD` there runs only the domain's refusal. No `GET` is served on such a path. - Anonymous floor order: at head, every anonymous `HEAD` row gets the anonymous `GET` answer. At base one row did not: the public `GET /share-links/:token/resolve` answered `501` (no service in this boot), and its `HEAD` answered `401`. **Side effects of `GET` dispatch.** A domain that forwards the request to a member still hands over the client's `HEAD`. The `/mcp` transport was handed `HEAD` on both doors, before and after. The `/approvals/act` member is handed a `GET` built by the domain, as before. A domain keyed on the dispatcher's verb now runs its `GET` branch for a `HEAD`, which is what the standalone server already does for the same request. ### `HEAD` on the hosted door, base → head (no `GET` row moved; standalone unchanged) | caller | path | `GET` | `HEAD` at base | `HEAD` at head | |---|---|---|---|---| | anonymous + signed in | `/mcp/skill` | `200` | `405`, `Allow: GET` | `200` | | anonymous + signed in | `/health`, `/ready` | `200` | `404 ROUTE_NOT_FOUND` | `200` | | anonymous + signed in | `/environments/env_m` (scoped root) | `200` | `404 ROUTE_NOT_FOUND` | `200` | | signed in | `/analytics/meta` | `200` | `404` (domain `handled: false`) | `200` | | signed in | `/ai/agents` | `200` | `501` | `200` | | signed in | `/data/account`, `/data/account/r1` | `503` (no data service) | `404` (domain `handled: false`) | `503` | | anonymous | `/share-links/tok/resolve` | `501` (public) | `401` | `501` | | anonymous (auth service present) | `/auth/config` | `200` | `404` | `200` (unit pin) | ### Other `GET`-serving domains with the same shape The card asks for these by name. All of them reach `dispatch()` through the same catch-all, so this change closes them too: - **Measured above:** `/health`, `/ready` (`methods: ['GET']`); the discovery root under `/environments/:id`; `analytics` (`/analytics/meta`); `ai` (`/ai/agents`); `data` (the reads); `share-links` (the public resolve floor); and the auth arm's `/auth/config`. - **Read in code, not measured:** their services were absent from the measuring boot, and each one's service-absence answer comes before its verb check, so both verbs answered alike there. These domains decide reads by `=== 'GET'`: - `i18n` (`m !== 'GET'` is not handled); - `automation` (its `GET` faces); - `notifications`; - `packages` (its `GET` faces); - `security` (`suggested-bindings`); - `share-links` (its other `GET` faces); - `meta` (the `!method || method === 'GET'` reads). ## Tests - New `packages/adapters/hono/src/hono-head-dispatched-as-get.test.ts` (4 cases; the dispatcher is this package's stub): - `HEAD /mcp/skill` reaches `dispatch()` as `GET` beside the client's `HEAD` request, and its answer is the `GET` answer's status and headers with an empty body. The fixture is the skill domain's real result shape. - A refused `GET` (`405`, `Allow: POST`, `METHOD_NOT_ALLOWED`, `httpStatus` 405) gets the same status and headers on `HEAD`, with no body. - Every other verb (`GET POST PUT PATCH DELETE OPTIONS`) reaches `dispatch()` as sent. - `HEAD /auth/config` gets the public config's status and headers with no body, and better-auth is not asked. - New `packages/qa/http-conformance/src/hono-head-as-get.conformance.test.ts` (24 cases). It uses the real `HttpDispatcher` and the real `createHonoApp` pipeline (`app.request`), beside the standalone server: - 12 rows, each asserting: the `GET` status, plus `code` and `httpStatus` for a refused `GET`; `HEAD` status and headers equal to the `GET`'s; empty `HEAD` body; and the `Allow` value (`POST` on the two `405` rows, absent otherwise). - For the 10 rows both doors serve, the hosted `HEAD` status and `Allow` equal the standalone `HEAD`'s. - `HEAD /mcp/skill` carries the skill's `content-type`, `content-disposition` and `cache-control` on both doors. - Only the verb moves: the `/mcp` transport is handed `HEAD` on both doors. - `packages/runtime/src/domains/approvals-act.test.ts`: new case. A `HEAD` request dispatched as `GET` is still forwarded to the member as a `GET`, and is answered with no body. - PR #24244's standalone pins, run and green: - `packages/runtime/src/mcp-skill-method-not-allowed.hono.integration.test.ts` - `actions-every-verb.hono.integration.test.ts` - `keys-every-verb.hono.integration.test.ts` - `notifications-every-verb.hono.integration.test.ts` - `dispatcher-body-after-anonymous-floor.hono.integration.test.ts` and `http-dispatcher.mcp.test.ts` (7 files, 291 tests). - Controls kept green: `hono-approvals-act.conformance.test.ts` (its `HEAD` pin holds both doors equal), `hono-webhooks-redeliver.conformance.test.ts` (`HEAD` stays `404`) and `hono-meta-item-read-gate.conformance.test.ts`. - Package runs: - `@objectstack/hono` `test`: 10 files, 211 tests, exit 0. `typecheck`: exit 0. Both at `379b734a2`. - `@objectstack/http-conformance` `test`: 16 files, 214 tests, exit 0. `typecheck`: exit 0. Both at `379b734a2`. - `@objectstack/runtime` `test`: 416 files, 6548 passed and 19 skipped, exit 0. `typecheck`: exit 0. Both at `0a5693634`; no runtime file changed after that commit. - The merge of `origin/main` at `4f14775b4` brought only `scripts/pm/dispatch-gates*`. ### One-time ablations (fix committed first, `scripts/ablation-replace.mjs`, wrap mode, restore proven: blob equals `HEAD` and `git diff HEAD` is empty) 1. **`dispatchedMethod`.** Mutated `return method === 'HEAD' ? 'GET' : method;` to `return method;`. Anchor count 1 → 0; blob `4f962dbb6cfd` → `aa3f8f87edab`. The subject resolves from source in both suites (the hono package itself, and the http-conformance alias of `@objectstack/hono` to `src`), so no build leg. - Hono unit: 3 failed, 1 passed. The every-other-verb control stays green. - Conformance: 13 failed, 11 passed. The 11 are the controls: non-`GET` paths, anonymous-floor rows that matched at base, and the `/mcp` verb row. - Restored to `4f962dbb6cfd`. 2. **The approvals key.** Mutated `if (request?.method === 'HEAD') {` to `if (method === 'HEAD') {`. Blob `67a8a4b44bf3` → `ab7e441de94c`. - `approvals-act.test.ts`: 1 failed, 12 passed (`expected 'HEAD' to be 'GET'`). - Restored. - The conformance leg of the same mutation was read before the runtime rebuild: `hono-approvals-act`'s `HEAD` pin was red, with the hosted door at `405` and `Allow: GET, POST`. The rebuilt `dist` then went green. ## Gates The gate list is derived by `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack` (no paths) at the final head `4f14775b4`. It gives 66 commands, the same list as at `0a5693634` and at `379b734a2`. - **All 66 run at `4f14775b4`: all exit 0.** Each exit code was captured before any pipe. These include: - `pnpm check:dispatcher-error-vocabulary` - `pnpm check:error-status-conformance` ("every derivable runtime status is documented, and every documented status is reachable") - `pnpm check:route-envelope` - `pnpm check:nul-bytes` (OK, no raw control bytes) - `pnpm check:changeset-gate-self-tests` - `node scripts/check-changeset-no-major.mjs --base origin/main` - `pnpm check:cross-package-test-inputs` - `pnpm check:test-source-alias` - `pnpm check:type-check-coverage` and `pnpm check:type-check-debt` - `pnpm check:dual-build-cjs-loads` - **`--ran` reconciliation:** `66 derived famil(ies) accounted for, 66 run, 0 NOT-MEASURED (a DERIVED zero, all 66 recorded an exit code and none of them is 3)`. - **First pass at `0a5693634`:** two commands exited 3 as prerequisite refusals, not measured failures. Both were re-run: - `check-plugin-teardown-shape --self-test` needed its pinned fixture commit, which was fetched. - `check:dual-build-cjs-loads` needed every workspace `dist`. - **ESLint over the changed files:** `pnpm exec eslint --no-inline-config` over the five changed source and test files, exit 0, no output. The repo-wide `pnpm lint` is CI's. - **Not run locally:** `@objectstack/runtime`'s `test:repo` project (CI's `Test Core`). The diff edits no test in that project. - **CI:** the PR's check-runs are the reading for every family CI owns. ## Acceptance notes - **A finding, reported to the PM, not fixed here.** On a `createHonoApp` host, `GET /api/v1/mcp/skill` serves the skill as an SSE frame of a JSON string: the body is `data: "# skill"` followed by a blank line, not the markdown. The `content-type` is doubled (`text/markdown; charset=utf-8, text/markdown; charset=utf-8`) and `cache-control` reads `no-cache, no-store`. The cause is `toResponse`'s `events` stream arm in `packages/adapters/hono/src/index.ts`: it SSE-frames every event unless `vercelDataStream` is set, and it merges its own capitalised headers with the domain's lowercase ones. `packages/runtime/src/domains/mcp.ts` says string events are "written verbatim" on every adapter. The standalone server serves the raw markdown with `cache-control: no-store` (PR #24244's pin). This change does not touch it, and the new pins assert only `toContain` on those two headers and a non-empty `GET` body, so nothing pins the defect. - The auth arm's legacy fallback `dispatcher.handleAuth(path, method, …)` still passes the raw verb. The auth domain does not read it (`_method`), so no answer differs, and it is unchanged. - A `HEAD` on a `GET` whose answer is an `events` stream still runs the stream's producer; Hono discards the body. The standalone server does the same for the same request, since it runs the `GET` handler too. Noted, not changed. --- _Generated by [Claude Code](https://claude.ai/code/session_01SYEJqDL3NXxrJRBVqaMu9T)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent e15897c commit 9822b05

6 files changed

Lines changed: 469 additions & 9 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
'@objectstack/hono': patch
3+
'@objectstack/runtime': patch
4+
---
5+
6+
fix(hono): on a `createHonoApp` host a `HEAD` is answered as its `GET` (no body), as the standalone server answers it; `HEAD /api/v1/mcp/skill` no longer answers `405` with `Allow: GET`
7+
8+
Clause-②: no
9+
10+
`createHonoApp`'s `${prefix}/*` catch-all handed the dispatcher the request's raw verb. Hono answers a `HEAD` from the `GET` route, but the verb still read `HEAD`, and the dispatcher's domains decide by comparing it with `GET`, so a `HEAD` was not answered as its `GET` on this host. Measured: `HEAD /api/v1/mcp/skill` answered `405 METHOD_NOT_ALLOWED` with `Allow: GET`; `/health`, `/ready` and the scoped root `/environments/:id` answered `404 ROUTE_NOT_FOUND`; signed in, `/analytics/meta` answered `404` and `/ai/agents` `501`; anonymous, the public `/share-links/:token/resolve` answered `401` where `GET` answers `501`. With an auth service, `HEAD /auth/config` answered `404` (it was forwarded to better-auth instead of answered as the `GET`).
11+
12+
- **`@objectstack/hono`.** The catch-all now dispatches a `HEAD` as `GET`, and the `/auth/config` branch answers a `HEAD` as its `GET`. Every dispatcher route answers `HEAD` with its `GET` answer's status and headers, and Hono drops the body. A path that serves no `GET` keeps its `GET` answer for `HEAD` (its `405` and `Allow`, or `401` to an anonymous caller). The standalone server (`HonoServerPlugin` with the dispatcher plugin) already answered `HEAD` this way. Only the verb changes: a domain that forwards the request (the `/mcp` transport, the `/approvals/act` page) is still handed the client's `HEAD` request.
13+
- **`@objectstack/runtime`.** The `/approvals/act` domain decides whether a request is a `HEAD` from the forwarded request's own method, not from the dispatcher's verb. So a `HEAD` still reaches the approvals member as a `GET` and is answered with no body.
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* [#24245] A `HEAD` reaches `dispatch()` as the `GET` it is answered from.
5+
*
6+
* Hono answers a `HEAD` from the `GET` route — it routes the request as `GET`
7+
* and keeps that answer's status and headers with no body — but `c.req.method`
8+
* still reads `HEAD`, and the catch-all handed that straight to `dispatch()`.
9+
* Every dispatcher domain decides its verb by comparing it with `'GET'`, so a
10+
* `HEAD` was not answered as its `GET` on this host (`HEAD /api/v1/mcp/skill`:
11+
* `405` with `Allow: GET` while `GET` served the skill). The standalone server
12+
* hands `dispatch()` a literal `'GET'` for the same request.
13+
*
14+
* What is pinned here, with the dispatcher a fixture (this package's config
15+
* aliases `@objectstack/runtime` to a stub):
16+
* 1. the verb `dispatch()` receives for `HEAD` is `GET`, and the request
17+
* beside it is still the client's `HEAD` — only the verb moves;
18+
* 2. the `HEAD` answer is the `GET` answer's status and headers with no body,
19+
* a stream result and a `405` with `Allow` alike;
20+
* 3. every other verb reaches `dispatch()` as it was sent;
21+
* 4. the auth arm's `/auth/config` branch answers a `HEAD` as its `GET`.
22+
*
23+
* The same rows through the REAL dispatcher and both doors are
24+
* `packages/qa/http-conformance/src/hono-head-as-get.conformance.test.ts`.
25+
*/
26+
27+
import { describe, it, expect, vi, beforeEach } from 'vitest';
28+
29+
interface Seen { method: string; path: string; requestMethod: string }
30+
const seen: Seen[] = [];
31+
32+
/** What the fixture dispatcher answers, per sub-path. */
33+
function answer(path: string): any {
34+
if (path === '/mcp/skill') {
35+
// The `/mcp/skill` domain's result shape (`runtime/src/domains/mcp.ts`).
36+
return {
37+
handled: true,
38+
result: {
39+
type: 'stream',
40+
status: 200,
41+
contentType: 'text/markdown; charset=utf-8',
42+
headers: {
43+
'content-type': 'text/markdown; charset=utf-8',
44+
'content-disposition': 'inline; filename="SKILL.md"',
45+
'cache-control': 'no-store',
46+
},
47+
events: (async function* () { yield '# skill'; })(),
48+
},
49+
};
50+
}
51+
if (path === '/keys') {
52+
return {
53+
handled: true,
54+
response: {
55+
status: 405,
56+
headers: { Allow: 'POST' },
57+
body: { success: false, error: { code: 'METHOD_NOT_ALLOWED', message: 'Method not allowed — use POST', httpStatus: 405 } },
58+
},
59+
};
60+
}
61+
return { handled: true, response: { status: 200, body: { success: true, data: { path } } } };
62+
}
63+
64+
const mockDispatcher = {
65+
getDiscoveryInfo: vi.fn().mockReturnValue({ version: '1.0', routes: {} }),
66+
handleAuth: vi.fn(async () => ({ handled: true, response: { status: 200, body: { ok: true } } })),
67+
dispatch: vi.fn(async (method: string, path: string, _body: unknown, _query: unknown, ctx: { request: Request }) => {
68+
seen.push({ method, path, requestMethod: ctx.request.method });
69+
return answer(path);
70+
}),
71+
};
72+
73+
vi.mock('@objectstack/runtime', () => ({
74+
HttpDispatcher: function HttpDispatcher() { return mockDispatcher; },
75+
}));
76+
77+
import { createHonoApp } from './index';
78+
79+
const PREFIX = '/api/v1';
80+
const kernel = { name: 'test-kernel' } as any;
81+
82+
/** Headers a transport adds on its own, independent of the route. */
83+
const TRANSPORT_HEADERS = new Set(['date', 'connection', 'keep-alive', 'content-length', 'transfer-encoding']);
84+
async function snapshot(res: Response) {
85+
return {
86+
status: res.status,
87+
headers: [...res.headers.entries()].filter(([k]) => !TRANSPORT_HEADERS.has(k)),
88+
body: await res.text(),
89+
};
90+
}
91+
92+
beforeEach(() => {
93+
seen.length = 0;
94+
mockDispatcher.dispatch.mockClear();
95+
mockDispatcher.handleAuth.mockClear();
96+
});
97+
98+
describe('[#24245] the catch-all dispatches a HEAD as GET', () => {
99+
it('HEAD /mcp/skill: dispatch() receives GET beside the client\'s HEAD request, and the answer is the GET\'s with no body', async () => {
100+
const app = createHonoApp({ kernel, prefix: PREFIX, cors: false });
101+
102+
const head = await snapshot(await app.request(`http://hosted.test${PREFIX}/mcp/skill`, { method: 'HEAD' }));
103+
const get = await snapshot(await app.request(`http://hosted.test${PREFIX}/mcp/skill`));
104+
105+
expect(seen).toEqual([
106+
{ method: 'GET', path: '/mcp/skill', requestMethod: 'HEAD' },
107+
{ method: 'GET', path: '/mcp/skill', requestMethod: 'GET' },
108+
]);
109+
expect(get.status).toBe(200);
110+
expect(get.body).not.toBe('');
111+
expect(head.status).toBe(200);
112+
expect(head.headers).toEqual(get.headers);
113+
expect(head.headers.find(([k]) => k === 'content-type')?.[1]).toContain('text/markdown');
114+
expect(head.body).toBe('');
115+
});
116+
117+
it('HEAD on a path whose GET is refused: the GET\'s 405 and its Allow, no body', async () => {
118+
const app = createHonoApp({ kernel, prefix: PREFIX, cors: false });
119+
120+
const getRes = await app.request(`http://hosted.test${PREFIX}/keys`);
121+
const getBody = (await getRes.clone().json()) as { error: { code: string; httpStatus: number } };
122+
const get = await snapshot(getRes);
123+
const head = await snapshot(await app.request(`http://hosted.test${PREFIX}/keys`, { method: 'HEAD' }));
124+
125+
expect(get.status).toBe(405);
126+
expect(getBody.error.code).toBe('METHOD_NOT_ALLOWED');
127+
expect(getBody.error.httpStatus).toBe(405);
128+
expect(head.status).toBe(405);
129+
expect(head.headers).toContainEqual(['allow', 'POST']);
130+
expect(head.headers).toEqual(get.headers);
131+
expect(head.body).toBe('');
132+
expect(seen.map((s) => s.method)).toEqual(['GET', 'GET']);
133+
});
134+
135+
it('every other verb reaches dispatch() as it was sent', async () => {
136+
const app = createHonoApp({ kernel, prefix: PREFIX, cors: false });
137+
138+
for (const method of ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS']) {
139+
await app.request(`http://hosted.test${PREFIX}/data/task`, { method });
140+
}
141+
expect(seen.map((s) => [s.method, s.requestMethod])).toEqual([
142+
['GET', 'GET'],
143+
['POST', 'POST'],
144+
['PUT', 'PUT'],
145+
['PATCH', 'PATCH'],
146+
['DELETE', 'DELETE'],
147+
['OPTIONS', 'OPTIONS'],
148+
]);
149+
});
150+
});
151+
152+
describe('[#24245] the auth arm answers HEAD /auth/config as its GET', () => {
153+
it('the public config\'s status and headers with no body, and better-auth is not asked', async () => {
154+
const handleRequest = vi.fn(async () => new Response('{"message":"Not found"}', { status: 404 }));
155+
const authKernel = {
156+
getServiceAsync: vi.fn().mockResolvedValue({
157+
getPublicConfig: () => ({ features: { sso: false } }),
158+
handleRequest,
159+
ownsRoute: async () => false,
160+
}),
161+
} as any;
162+
const app = createHonoApp({ kernel: authKernel, prefix: PREFIX, cors: false });
163+
164+
const get = await snapshot(await app.request(`http://hosted.test${PREFIX}/auth/config`));
165+
const head = await snapshot(await app.request(`http://hosted.test${PREFIX}/auth/config`, { method: 'HEAD' }));
166+
167+
expect(get.status).toBe(200);
168+
expect(JSON.parse(get.body)).toEqual({ success: true, data: { features: { sso: false } } });
169+
expect(head.status).toBe(200);
170+
expect(head.headers).toEqual(get.headers);
171+
expect(head.body).toBe('');
172+
expect(handleRequest).not.toHaveBeenCalled();
173+
});
174+
});

‎packages/adapters/hono/src/index.ts‎

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,40 @@ function readDispatchQuery(c: Context): Record<string, string | string[]> {
537537
) as Record<string, string | string[]>;
538538
}
539539

540+
/**
541+
* [#24245] The verb the catch-all hands `dispatch()`, and the one the auth
542+
* arm's `/auth/config` branch compares: the request's own, except that a
543+
* `HEAD` goes as `GET`.
544+
*
545+
* Hono answers a `HEAD` from the `GET` route: it routes the request as `GET`
546+
* and returns that answer's status and headers with no body. `c.req.method`
547+
* still reads `HEAD`, though, and the dispatcher decides a verb by comparing it
548+
* with `'GET'` (a domain's `methods`, its branches, the discovery root). So the
549+
* catch-all handed `dispatch()` a verb nothing serves, and a `HEAD` was not
550+
* answered as its `GET`. Measured through `app.request`, `GET` vs `HEAD`:
551+
* `/mcp/skill` `200` vs `405` with `Allow: GET`; `/health`, `/ready` and the
552+
* scoped root `/environments/:id` `200` vs `404 ROUTE_NOT_FOUND`; signed in,
553+
* `/analytics/meta` `200` vs `404`, `/ai/agents` `200` vs `501`; anonymous,
554+
* `/share-links/:token/resolve` (public) `501` vs `401`; with an auth service,
555+
* `/auth/config` `200` vs `404`.
556+
*
557+
* The standalone server hands `dispatch()` `GET` for the same request: both
558+
* `IHttpServer` transports route a `HEAD` to the `GET` handler (the
559+
* conformance suite pins "answers HEAD from GET routes without a body"), and
560+
* the dispatcher plugin's `GET` mounts pass a literal `'GET'`. This door now
561+
* does the same, so every domain answers `HEAD` exactly as it answers `GET`: a
562+
* path that serves no `GET` answers its `405` and `Allow`, an anonymous caller
563+
* gets the anonymous `GET` answer.
564+
*
565+
* Only the verb moves. `{ request: c.req.raw }` stays the client's `HEAD`
566+
* request, as the standalone mounts hand theirs, so a domain that forwards
567+
* the request (the `/mcp` transport, the `/approvals/act` member) sees the
568+
* method that was sent. The body is dropped by Hono's `HEAD` handling.
569+
*/
570+
function dispatchedMethod(method: string): string {
571+
return method === 'HEAD' ? 'GET' : method;
572+
}
573+
540574
/**
541575
* Creates a full-featured Hono app with all ObjectStack route dispatchers.
542576
*
@@ -916,7 +950,10 @@ export function createHonoApp(options: ObjectStackHonoOptions): Hono {
916950
}
917951

918952
// Handle /auth/config endpoint specifically (not handled by better-auth)
919-
if (path === 'config' && method === 'GET' && authService) {
953+
// [#24245] A `HEAD` is answered as this `GET` too (`dispatchedMethod`), as
954+
// `plugin-auth`'s `GET` mount answers it on the standalone server; it was
955+
// forwarded to better-auth instead and answered `404`.
956+
if (path === 'config' && dispatchedMethod(method) === 'GET' && authService) {
920957
try {
921958
const config = (authService as any).getPublicConfig?.();
922959
if (config) {
@@ -1060,7 +1097,8 @@ export function createHonoApp(options: ObjectStackHonoOptions): Hono {
10601097
// [#23214] A repeated name stays an array (`readDispatchQuery`).
10611098
const queryParams = readDispatchQuery(c);
10621099

1063-
const result = await dispatcher.dispatch(method, subPath, read?.value, queryParams, { request: c.req.raw }, prefix);
1100+
// [#24245] A `HEAD` is dispatched as the `GET` it is answered from (`dispatchedMethod`).
1101+
const result = await dispatcher.dispatch(dispatchedMethod(method), subPath, read?.value, queryParams, { request: c.req.raw }, prefix);
10641102
// [#23914] A body this adapter could not parse, READ by the domain: the
10651103
// refusal is the answer, whatever the domain answered (see `readDispatchBody`).
10661104
const refusal = read?.refusalRead();

0 commit comments

Comments
 (0)