Public: anyone can read this; the crew can change it.
Signed-out /pricing and /templates are kept by the edge for a minute, like / and /explore #14667
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/14658-signed-out-pricing-and-templates-are-kep → main 2 commits fork
2 files
changed +22
−4
src/http/edge_cache.ts +4 −3
| @@ -23,11 +23,12 @@ export type IsPublicRepo = (owner: string, name: string) => boolean; | ||
| 23 | 23 | |
| 24 | 24 | /** |
| 25 | 25 | * The pages whose signed-out body is the same for everyone: home, explore, |
| 26 | * and the front page of a repository that exists and is public. Any other | |
| 27 | * path, however it is shaped (`/apps/new`, `/settings/x`), is not shared. | |
| 26 | * pricing, templates (no token, nonce or flash in them; the query is part of | |
| 27 | * the address the edge keys on), and the front page of a repository that exists and is public. Any | |
| 28 | * other path, however it is shaped (`/apps/new`, `/settings/x`), is not shared. | |
| 28 | 29 | */ |
| 29 | 30 | export function sharedPath(pathname: string, isPublicRepo: IsPublicRepo): boolean { |
| 30 | if (pathname === "/" || pathname === "/explore") return true; | |
| 31 | if (pathname === "/" || pathname === "/explore" || pathname === "/pricing" || pathname === "/templates") return true; | |
| 31 | 32 | const m = /^\/([^/]+)\/([^/]+)$/.exec(pathname); |
| 32 | 33 | return m !== null && isPublicRepo(m[1]!, m[2]!); |
| 33 | 34 | } |
test/web-budget.test.ts +18 −1
| @@ -5,7 +5,7 @@ import { tmpdir } from "node:os"; | ||
| 5 | 5 | import { join } from "node:path"; |
| 6 | 6 | import { createApp, type App } from "../src/app.ts"; |
| 7 | 7 | import { serve, type Servers } from "../src/http/server.ts"; |
| 8 | import { sharedCache } from "../src/http/edge_cache.ts"; | |
| 8 | import { EDGE_VARY, sharedCache } from "../src/http/edge_cache.ts"; | |
| 9 | 9 | import { commitToBranch, createLabel, createRepo } from "../src/actions/repos.ts"; |
| 10 | 10 | import { NO_PREFETCH_PATHS, NO_PREFETCH_QUERY, pageScriptAsset, pageScriptDir, pageScriptNamed, speculationAsset } from "../src/web/asset.ts"; |
| 11 | 11 | import { rawResponse } from "../src/web/pages/repo.ts"; |
| @@ -105,6 +105,23 @@ describe("web budgets (docs/web.md)", () => { | ||
| 105 | 105 | expect(sharedCache(new Request("http://x/"), "/ada/engine/issues", () => false)).toBe("no-cache"); |
| 106 | 106 | }); |
| 107 | 107 | |
| 108 | test("pricing and templates are shared signed out, private with a cookie, byte-identical per visitor", async () => { | |
| 109 | for (const path of ["/pricing", "/templates"]) { | |
| 110 | const a = await fetch(base + path, { headers: { "x-request-id": "visitor-a" } }); | |
| 111 | const b = await fetch(base + path, { headers: { "x-request-id": "visitor-b" } }); | |
| 112 | expect(a.status).toBe(200); | |
| 113 | expect(a.headers.get("cache-control")).toContain("s-maxage=60"); | |
| 114 | expect(a.headers.get("vary")).toContain(EDGE_VARY); | |
| 115 | expect(await a.text()).toBe(await b.text()); | |
| 116 | const signedIn = await fetch(base + path, { headers: { cookie } }); | |
| 117 | expect(signedIn.headers.get("cache-control") ?? "").not.toContain("s-maxage"); | |
| 118 | const stray = await fetch(base + path, { headers: { cookie: "forge_order=x" } }); | |
| 119 | expect(stray.headers.get("cache-control") ?? "").not.toContain("s-maxage"); | |
| 120 | expect(sharedCache(new Request("http://x" + path), path, () => false)).toContain("s-maxage=60"); | |
| 121 | expect(sharedCache(new Request("http://x" + path, { headers: { cookie: "a=b" } }), path, () => false)).toBe("no-cache"); | |
| 122 | } | |
| 123 | }); | |
| 124 | ||
| 108 | 125 | test("back/forward cache: no no-store, no unload handlers", async () => { |
| 109 | 126 | for (const init of [{}, { headers: { cookie } }]) { |
| 110 | 127 | const res = await fetch(base + "/", init); |
new above
offline