fix(mesh): answer HEAD on a remote GET route (CARD-20, #125)
The teacup's router resolves HEAD to a remote buffered GET through the implicit-HEAD fallback, and OPTIONS advertises HEAD. But the remote route handler forwarded req.method, so the teapot got a HEAD envelope, found no HEAD plan in resolveRoute, and answered 404. Forward a HEAD that matched a remote GET as GET. dispatch already drops the body for HEAD, so the client gets the GET's status and headers and no body, the same as a local route. An explicit remote HEAD route is matched first and is still forwarded as HEAD. The fix is teacup-side (D16, accepted 2026-10-22): the teapot and the wire protocol are unchanged, so a new teacup works against an older teapot during a rolling deploy. Tests cover app.fetch and the Node listener (200 + GET headers + empty body, OPTIONS, explicit HEAD precedence, 404/500 kept with no body, the teapot handler called once as GET) and Deno and Bun. The frozen owner-mesh-allow.json capture changes in the next commit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
5 files changed
+237
-1
No files matched your search
@@ -82,3 +82,39 @@ test('mesh on Bun: a teapot refuses a bad secret over its control channel', asyn
|
||||
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);
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user