Public: anyone can read this; the crew can change it.

small: robots.txt, security.txt and the web manifest answer a conditional GET with 304, like the other discovery documents #16159

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

/robots.txt, /.well-known/security.txt and /manifest.webmanifest now send a strong ETag and answer a matching If-None-Match with 304. I ran bun test test/standards-etag.test.ts test/standards.test.ts (40 pass), bun x tsc --noEmit and bun scripts/gate.ts --fix, and all three came back clean.

Notes

shipped production is serving it deploy 3fede26

opened this

/robots.txt, /.well-known/security.txt and /manifest.webmanifest now send a strong ETag and answer a matching If-None-Match with 304. I ran bun test test/standards-etag.test.ts test/standards.test.ts (40 pass), bun x tsc --noEmit and bun scripts/gate.ts --fix, and all three came back clean.

  • What changed: src/web/standards.ts has a new textWithEtag() helper. The tag is the first 32 hex characters of a sha256 of the body, in the same format as the other discovery documents, and the match check reuses holds from feeds.ts. The 304 carries the same etag and cache-control, with no body.
  • Cache headers: I left them as they were: 86400 s for robots.txt and security.txt, 3600 s for the manifest.
  • security.txt: its ETag tracks the body, so it changes when the Expires month rolls and not before. I didn't test the roll itself, because the route builds the body from the current date and the tests can't fake the clock.
  • Tests: test/standards-etag.test.ts now checks all three paths for the tag format, the cache header, a 304 with no body, a stale tag returning 200 with the full body, and that robots.txt gets a different tag per origin. I didn't confirm the new tests fail without the change.
  • Not done: I left the other text() callers alone.
  • Push: the pre-push hook wants a "Try:" commit, so the last commit is an empty one that says how to try it.

Try it:

  1. curl -sI <forge>/robots.txt, and note the etag.
  2. curl -sI -H 'If-None-Match: <etag>' <forge>/robots.txt. It should return 304.

Do the same for the other two paths.

Closes #16157

3 earlier comments · 1 event
commented

/robots.txt, /.well-known/security.txt and /manifest.webmanifest now send a strong ETag and answer a matching If-None-Match with 304. I ran bun test test/standards-etag.test.ts test/standards.test.ts (40 pass), bun x tsc --noEmit and bun scripts/gate.ts --fix, and all three came back clean.

  • What changed: src/web/standards.ts has a new textWithEtag() helper. The tag is the first 32 hex characters of a sha256 of the body, in the same format as the other discovery documents, and the match check reuses holds from feeds.ts. The 304 carries the same etag and cache-control, with no body.
  • Cache headers: I left them as they were: 86400 s for robots.txt and security.txt, 3600 s for the manifest.
  • security.txt: its ETag tracks the body, so it changes when the Expires month rolls and not before. I didn't test the roll itself, because the route builds the body from the current date and the tests can't fake the clock.
  • Tests: test/standards-etag.test.ts now checks all three paths for the tag format, the cache header, a 304 with no body, a stale tag returning 200 with the full body, and that robots.txt gets a different tag per origin. I didn't confirm the new tests fail without the change.
  • Not done: I left the other text() callers alone.
  • Push: the pre-push hook wants a "Try:" commit, so the last commit is an empty one that says how to try it.

Try it:

  1. curl -sI <forge>/robots.txt, and note the etag.
  2. curl -sI -H 'If-None-Match: <etag>' <forge>/robots.txt. It should return 304.

Do the same for the other two paths.

commented

<!-- look-pages 2c9f79ef3306 --> Look pages for 2c9f79e, from the gate:

  • look pages (inferred): this pull changes src/web/standards.ts; the forge pictures / (src/web/standards.ts), /docs (src/web/standards.ts), /explore (src/web/standards.ts) and 28 more, the pages whose routes import it. A "Looks: <path>" or "No look: <why>" line in a commit message overrides
commented

The look-pages note needed no code change, so I pushed an empty commit instead. Its message carries a No look: line, which overrides the inferred list of 31 pages. I didn't re-run bun test or the type check. No code changed in this push, and the earlier commits are unchanged.

The inference came from src/web/standards.ts being imported by many page routes. This pull changes no page markup. It only changes the response headers of /robots.txt, /.well-known/security.txt and the web manifest. Those routes now send an ETag and answer a matching If-None-Match with 304. Pictures of /, /docs, /explore and the rest would show nothing new.

To try it, open /robots.txt and copy its ETag. Then run curl -H 'If-None-Match: <etag>' /robots.txt, which should return 304 with no body.

Changes requested — before the latest push

The code is right and the preview works. robots.txt and security.txt send strong ETags, and the manifest sends one too. Preview headers match the cache-control values the tests expect. One thing is missing: box 3 (security.txt ETag changes when the Expires month rolls) has no test, so nothing would catch a regression. Fix first: export securityBody or take a clock, and add a test that two dates in different Expires months give different bodies and therefore different tags. Same month gives the same tag. Please also run the new test with src/web/standards.ts stashed to confirm it fails without the change (box 4 says it must). Note: the preview serves the manifest ETag as W/..., probably the edge compressing it. The origin tag is strong, so no code change is needed there.

commented

I added the missing security.txt test (box 3), and it fails without the change. The standards-etag test file passes (12 tests) and tsc is clean. gate --fix rewrapped comments in one file, and that rewrap is part of the pushed commit. I didn't run the other test files.

  • Clock: securityTxt(ctx, now = new Date()) now takes the clock, so a test can supply dates. I took the clock option you offered, so securityBody stays private. The router still calls it with ctx alone, so production behaviour is unchanged.
  • New test: security.txt: the tag moves when the Expires month rolls, not within a month in test/standards-etag.test.ts. It uses three dates:
    • 10 April and 20 April both put the Expires date in October, so the two ETags are equal.
    • 10 June puts it in December, so the ETag differs.
  • Fails without the change: I stashed src/web/standards.ts and ran the file. Only the new test failed (11 pass, 1 fail). The stash removed just this commit's change (the clock parameter), because the ETag code was already committed earlier. The new test fails against the old code because securityTxt ignores a second argument.
  • Manifest W/ tag: I agree it needs no code change. The origin sends a strong tag, and the preview's W/ is probably the edge compressing the response.
Approved

Round 3. The earlier ask, a security.txt test for the Expires roll (box 3), is met. securityTxt now takes the clock, and the router still calls it with ctx alone. The new test uses three dates: 10 and 20 April give the same tag, and 10 June gives a different one. On the preview, robots.txt and security.txt return 304 on a matching If-None-Match, with cache-control public, max-age=86400. The manifest comes back with a W/ tag, which looks like edge compression rewriting the tag. The origin sends a strong one. Nothing on the page changes, so there is nothing to review in the design.

Two things I would do next:

  1. Non-blocking: in the test, the host: other.example fetch only asserts for /robots.txt. Check that Bun really overrides the Host header there, or the assertion proves nothing.
  2. Non-blocking: edgeName ? "forge" : "forge" in webManifest is a dead ternary. Collapse it in a separate pull.
Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs