Depends on #140 (CARD-14). Review and merge after it. This branch stacks on feature/fprd-001c-cookies, so until #140 merges the diff against develop includes CARD-14's commit. Review only the top commit (feat(http): ETag and 304 …).
Implements CARD-15 (core #114) under decision D12 (on for static, opt-in for handlers) and rule 1a (static Cache-Control).
What changed and why
Static (always on):
StaticHit now holds { contentType, size, mtimeMs, cacheControl, read() } instead of the bytes. It is internal and not exported.
unmatchedOutcome sets ETag: W/"<size>-<mtimeMs base36>" and Last-Modified from the resolver's stat, plus Cache-Control. It decides the conditional request before calling read(), so a 304 never reads the file. HEAD no longer reads it either.
If-None-Match takes precedence; If-Modified-Since is used only when If-None-Match is absent, compared at one-second resolution.
static: { dir?, cacheControl? }:
Cache-Control: no-cache by default on 200 and 304.
normalizeStatic validates at boot. It throws on an unknown key, a non-string dir/cacheControl, or a cacheControl containing CR/LF.
static: true | '<dir>' is unchanged.
createApp({ etag: true }):
Off by default; anything but a boolean throws.
In dispatch, a buffered 200 to GET/HEAD gets a weak tag from 32-bit FNV-1a over the UTF-8 bytes plus the byte length (W/"<len36>-<hash36>"). It is computed before HEAD blanks the body.
A handler-set etag (any case) is kept and only compared.
Comparison is weak. Lists are split on commas outside quotes, and * is supported.
304 shape:
Every buffered 304 leaving dispatch passes through bodyless(): empty body, content-* headers dropped (except content-location), transfer-encoding dropped.
ETag, Vary, Cache-Control, Last-Modified and the injected security headers stay.
throw new NotModified() now goes through the same function. Before, it sent the JSON envelope's content-type; now it sends no body headers.
Mesh: a remote route is buffered on the teacup, so etag: true there tags it like a local route. No protocol change.
Unsure / conservative choices
Handler-set tags without etag: true. The card's rule 3 doesn't say whether a handler-set etag is compared when etag is off. I compare only under etag: true, following the AC "absent or false adds none (no silent partial behaviour)". Tested both ways.
Hash width. 32-bit FNV plus length; the card allows 32 or 64. Collisions can only happen between bodies of equal length.
Size format.<size> in the static tag is decimal and mtimeMs is floored, then base36. The card leaves the size radix open.
304s keep non-body headers such as set-cookie. Rule 6 lists what must be present, and I strip only the body-describing headers.
views-static.test.ts changed one line, from hit.body to hit.read(), because StaticHit changed.
Test evidence
New test/etag.test.ts covers T1–T10, the NotModified 304, static object form and validation, etag validation, and Node over a raw socket (T11). The readFile spy checks T1 on Node, Deno and Bun. New test/deno/etag.test.ts and test/bun/etag.test.ts run T1 + T5 on real Deno.serve/Bun.serve. Deno's own readFile re-enters itself with a file descriptor, so that suite counts only calls that name a path. test/edge/run.ts runs T5 on workerd. Static on the edge is N/A: static is a boot error there.
== npm run lint
exit 0
✖ 50 problems (0 errors, 50 warnings)
== npm run format:check
exit 0
All matched files use Prettier code style!
== npm run typecheck
exit 0
== npm run test
exit 0
Test Files 94 passed (94)
Tests 960 passed (960)
== npm run build
exit 0
ESM ⚡️ Build success in 26ms
CJS ⚡️ Build success in 26ms
DTS ⚡️ Build success in 927ms
== npm run complexity:check
exit 0
✓ cognitive complexity: every function ≤ 25
== npm run test:deno
exit 0
T3 serveDeno: an IPv6 peer is passed through as Deno reports it ... ok (702µs)
ok | 38 passed | 0 failed (4s)
== npm run test:bun
exit 0
28 pass
0 fail
== npm run test:edge
exit 0
edge (workerd via miniflare): HTTP 200 + cookies + etag/304 + body limits 413/413/200/413 + WS echo:hi + ws limits — PASS
edge (workerd): router parity — 1158 matcher cases + 55 app.fetch cases — PASS
Frozen router-parity captures are untouched.
Docs follow-up (CARD-12)
reference/createapp.md: the etag option, the static object form (dir, cacheControl), and what static responses now carry (ETag, Last-Modified, Cache-Control: no-cache, 304).
guides/html.md: revalidation for static assets, and the immutable recipe for hashed assets.
**Depends on #140 (CARD-14). Review and merge after it.** This branch stacks on `feature/fprd-001c-cookies`, so until #140 merges the diff against `develop` includes CARD-14's commit. Review only the top commit (`feat(http): ETag and 304 …`).
Implements **CARD-15** (core #114) under decision **D12** (on for static, opt-in for handlers) and rule 1a (static `Cache-Control`).
## What changed and why
- **Static (always on):**
- `StaticHit` now holds `{ contentType, size, mtimeMs, cacheControl, read() }` instead of the bytes. It is internal and not exported.
- `unmatchedOutcome` sets `ETag: W/"<size>-<mtimeMs base36>"` and `Last-Modified` from the resolver's `stat`, plus `Cache-Control`. It decides the conditional request **before** calling `read()`, so a `304` never reads the file. `HEAD` no longer reads it either.
- `If-None-Match` takes precedence; `If-Modified-Since` is used only when `If-None-Match` is absent, compared at one-second resolution.
- **`static: { dir?, cacheControl? }`:**
- `Cache-Control: no-cache` by default on 200 and 304.
- `normalizeStatic` validates at boot. It throws on an unknown key, a non-string `dir`/`cacheControl`, or a `cacheControl` containing CR/LF.
- `static: true | '<dir>'` is unchanged.
- **`createApp({ etag: true })`:**
- Off by default; anything but a boolean throws.
- In `dispatch`, a buffered `200` to GET/HEAD gets a weak tag from 32-bit FNV-1a over the UTF-8 bytes plus the byte length (`W/"<len36>-<hash36>"`). It is computed before HEAD blanks the body.
- A handler-set `etag` (any case) is kept and only compared.
- Comparison is weak. Lists are split on commas outside quotes, and `*` is supported.
- **304 shape:**
- Every buffered 304 leaving `dispatch` passes through `bodyless()`: empty body, `content-*` headers dropped (except `content-location`), `transfer-encoding` dropped.
- `ETag`, `Vary`, `Cache-Control`, `Last-Modified` and the injected security headers stay.
- `throw new NotModified()` now goes through the same function. Before, it sent the JSON envelope's `content-type`; now it sends no body headers.
- **Mesh:** a remote route is buffered on the teacup, so `etag: true` there tags it like a local route. No protocol change.
## Unsure / conservative choices
- **Handler-set tags without `etag: true`.** The card's rule 3 doesn't say whether a handler-set `etag` is compared when `etag` is off. I compare **only under `etag: true`**, following the AC "absent or false adds none (no silent partial behaviour)". Tested both ways.
- **Hash width.** 32-bit FNV plus length; the card allows 32 or 64. Collisions can only happen between bodies of equal length.
- **Size format.** `<size>` in the static tag is decimal and `mtimeMs` is floored, then base36. The card leaves the size radix open.
- `304`s keep non-body headers such as `set-cookie`. Rule 6 lists what *must* be present, and I strip only the body-describing headers.
- `views-static.test.ts` changed one line, from `hit.body` to `hit.read()`, because `StaticHit` changed.
## Test evidence
New `test/etag.test.ts` covers T1–T10, the `NotModified` 304, `static` object form and validation, `etag` validation, and Node over a raw socket (T11). The `readFile` spy checks T1 on Node, Deno and Bun. New `test/deno/etag.test.ts` and `test/bun/etag.test.ts` run T1 + T5 on real `Deno.serve`/`Bun.serve`. Deno's own `readFile` re-enters itself with a file descriptor, so that suite counts only calls that name a path. `test/edge/run.ts` runs T5 on workerd. Static on the edge is N/A: `static` is a boot error there.
```
== npm run lint
exit 0
✖ 50 problems (0 errors, 50 warnings)
== npm run format:check
exit 0
All matched files use Prettier code style!
== npm run typecheck
exit 0
== npm run test
exit 0
Test Files 94 passed (94)
Tests 960 passed (960)
== npm run build
exit 0
ESM ⚡️ Build success in 26ms
CJS ⚡️ Build success in 26ms
DTS ⚡️ Build success in 927ms
== npm run complexity:check
exit 0
✓ cognitive complexity: every function ≤ 25
== npm run test:deno
exit 0
T3 serveDeno: an IPv6 peer is passed through as Deno reports it ... ok (702µs)
ok | 38 passed | 0 failed (4s)
== npm run test:bun
exit 0
28 pass
0 fail
== npm run test:edge
exit 0
edge (workerd via miniflare): HTTP 200 + cookies + etag/304 + body limits 413/413/200/413 + WS echo:hi + ws limits — PASS
edge (workerd): router parity — 1158 matcher cases + 55 app.fetch cases — PASS
```
Frozen router-parity captures are untouched.
## Docs follow-up (CARD-12)
- `reference/createapp.md`: the `etag` option, the `static` object form (`dir`, `cacheControl`), and what static responses now carry (`ETag`, `Last-Modified`, `Cache-Control: no-cache`, `304`).
- `guides/html.md`: revalidation for static assets, and the `immutable` recipe for hashed assets.
Owner decision (2026-10-23): with etag off, a handler-set etag header does not trigger a 304. Accepted as implemented. Not merging yet: implementation review first.
Owner decision (2026-10-23): with `etag` off, a handler-set `etag` header does not trigger a 304. Accepted as implemented. Not merging yet: implementation review first.
Implementation review done on 2026-10-23: a Codex review of all 12 sprint PRs, with each finding verified. The P1s in #142 and the P3 in #149 are fixed. The owner (Chrnx) authorized merging in order, each one rebased on develop with CI green. This supersedes the earlier "not merging yet" note.
Implementation review done on 2026-10-23: a Codex review of all 12 sprint PRs, with each finding verified. The P1s in #142 and the P3 in #149 are fixed. The owner (Chrnx) authorized merging in order, each one rebased on develop with CI green. This supersedes the earlier "not merging yet" note.
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>
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Depends on #140 (CARD-14). Review and merge after it. This branch stacks on
feature/fprd-001c-cookies, so until #140 merges the diff againstdevelopincludes CARD-14's commit. Review only the top commit (feat(http): ETag and 304 …).Implements CARD-15 (core #114) under decision D12 (on for static, opt-in for handlers) and rule 1a (static
Cache-Control).What changed and why
StaticHitnow holds{ contentType, size, mtimeMs, cacheControl, read() }instead of the bytes. It is internal and not exported.unmatchedOutcomesetsETag: W/"<size>-<mtimeMs base36>"andLast-Modifiedfrom the resolver'sstat, plusCache-Control. It decides the conditional request before callingread(), so a304never reads the file.HEADno longer reads it either.If-None-Matchtakes precedence;If-Modified-Sinceis used only whenIf-None-Matchis absent, compared at one-second resolution.static: { dir?, cacheControl? }:Cache-Control: no-cacheby default on 200 and 304.normalizeStaticvalidates at boot. It throws on an unknown key, a non-stringdir/cacheControl, or acacheControlcontaining CR/LF.static: true | '<dir>'is unchanged.createApp({ etag: true }):dispatch, a buffered200to GET/HEAD gets a weak tag from 32-bit FNV-1a over the UTF-8 bytes plus the byte length (W/"<len36>-<hash36>"). It is computed before HEAD blanks the body.etag(any case) is kept and only compared.*is supported.dispatchpasses throughbodyless(): empty body,content-*headers dropped (exceptcontent-location),transfer-encodingdropped.ETag,Vary,Cache-Control,Last-Modifiedand the injected security headers stay.throw new NotModified()now goes through the same function. Before, it sent the JSON envelope'scontent-type; now it sends no body headers.etag: truethere tags it like a local route. No protocol change.Unsure / conservative choices
etag: true. The card's rule 3 doesn't say whether a handler-setetagis compared whenetagis off. I compare only underetag: true, following the AC "absent or false adds none (no silent partial behaviour)". Tested both ways.<size>in the static tag is decimal andmtimeMsis floored, then base36. The card leaves the size radix open.304s keep non-body headers such asset-cookie. Rule 6 lists what must be present, and I strip only the body-describing headers.views-static.test.tschanged one line, fromhit.bodytohit.read(), becauseStaticHitchanged.Test evidence
New
test/etag.test.tscovers T1–T10, theNotModified304,staticobject form and validation,etagvalidation, and Node over a raw socket (T11). ThereadFilespy checks T1 on Node, Deno and Bun. Newtest/deno/etag.test.tsandtest/bun/etag.test.tsrun T1 + T5 on realDeno.serve/Bun.serve. Deno's ownreadFilere-enters itself with a file descriptor, so that suite counts only calls that name a path.test/edge/run.tsruns T5 on workerd. Static on the edge is N/A:staticis a boot error there.Frozen router-parity captures are untouched.
Docs follow-up (CARD-12)
reference/createapp.md: theetagoption, thestaticobject form (dir,cacheControl), and what static responses now carry (ETag,Last-Modified,Cache-Control: no-cache,304).guides/html.md: revalidation for static assets, and theimmutablerecipe for hashed assets.c86d298fd4tofc1db2dbabOwner decision (2026-10-23): with
etagoff, a handler-setetagheader does not trigger a 304. Accepted as implemented. Not merging yet: implementation review first.Implementation review done on 2026-10-23: a Codex review of all 12 sprint PRs, with each finding verified. The P1s in #142 and the P3 in #149 are fixed. The owner (Chrnx) authorized merging in order, each one rebased on develop with CI green. This supersedes the earlier "not merging yet" note.
fc1db2dbabtoea19ee21b7Conditional 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>ea19ee21b7tod32fc9f8d7