feat(http): ETag and 304 for static files and buffered responses (CARD-15, #114)
Conditional GETs were never answered: every revalidation re-downloaded
the file or response.
- Static (D12, always on): a hit carries W/"<size>-<mtimeMs base36>",
Last-Modified and Cache-Control from the stat the resolver already did.
A matching If-None-Match, or If-Modified-Since when If-None-Match is
absent, answers 304 before the file is read. StaticHit now carries the
stat and a read() for the bytes, and HEAD no longer reads either.
- static: { dir?, cacheControl? } (rule 1a): Cache-Control defaults to
no-cache so browsers revalidate rather than reuse a file for a lifetime
guessed from Last-Modified. An unknown key or CR/LF throws at boot.
- createApp({ etag: true }) (off by default, boolean only): a buffered 200
to GET/HEAD gets a weak tag from a 32-bit FNV-1a hash of its UTF-8 bytes
plus its length, computed before HEAD blanks the body. A handler-set
etag is kept and only compared. Weak comparison, lists split outside
quotes, and * are supported.
- Every buffered 304 leaves dispatch bodiless, with its content-* headers
dropped, so NotModified matches the ETag path on every adapter.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
14 files changed
+706
-37
No files matched your search
Vendored
+17
@@ -0,0 +1,17 @@
|
||||
// CARD-15 (#114): one graph for the Deno, Bun and edge ETag checks (T11), so each runtime answers
|
||||
// the same T1/T5 the Node suite (test/etag.test.ts) does.
|
||||
import { Route, Get, Module } from '../../src/index';
|
||||
|
||||
@Route('/h')
|
||||
class EtagCtl {
|
||||
@Get('/json')
|
||||
json() {
|
||||
return { n: 1 };
|
||||
}
|
||||
}
|
||||
|
||||
@Module({ mountpoint: '/', controllers: [EtagCtl] })
|
||||
export class EtagModule {}
|
||||
|
||||
/** A committed file the static checks can serve: `asset.txt` under `test/fixtures/views`. */
|
||||
export const STATIC_DIR = 'test/fixtures/views';
|
||||
Reference in new issue
Block a user