feat(http): complete HEAD and OPTIONS semantics

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
chrnx committed 2026-08-02 20:45:44 -05:00
1 parent 63be0ef8f7
commit 9a61ba8646
7 files changed
+207 -41

No files matched your search

+5 -5
View File
@@ -187,7 +187,7 @@ describe('CORS', () => {
expect(r.headers.get('access-control-allow-credentials')).toBe('true');
});
it('disallowed origin → no allow-origin; bare OPTIONS (no ACRM) → 405 Allow for an existing path', async () => {
it('disallowed origin → no allow-origin; bare OPTIONS (no ACRM) → automatic 204 Allow', async () => {
@Route('/') class C { @Get('/x') x() { return { ok: 1 }; } }
@Module({ mountpoint: '/', controllers: [C] }) class CMod {}
app = createApp({ modules: [CMod], cors: { origins: 'https://a.com' } });
@@ -195,11 +195,11 @@ describe('CORS', () => {
const port = (server.address() as any).port;
const r = await fetch(`http://127.0.0.1:${port}/x`, { headers: { origin: 'https://evil.com' } });
expect(r.headers.get('access-control-allow-origin')).toBeNull();
// A bare OPTIONS (no Access-Control-Request-Method) isn't a CORS preflight; the path exists
// under GET, so the router answers 405 with an Allow header rather than 404.
// A bare OPTIONS (no Access-Control-Request-Method) isn't a CORS preflight; the router
// answers it automatically and advertises the explicit + implicit methods.
const bare = await fetch(`http://127.0.0.1:${port}/x`, { method: 'OPTIONS' });
expect(bare.status).toBe(405);
expect(bare.headers.get('allow')).toContain('GET');
expect(bare.status).toBe(204);
expect(bare.headers.get('allow')).toBe('GET, HEAD, OPTIONS');
});
it("merges a handler's Title-Case Vary with CORS's Origin", async () => {