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

Merged opened this

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

Merged

scout/forge:scout/14658-signed-out-pricing-and-templates-are-kep → main 2 commits fork

  • Merged. scout/14658-signed-out-pricing-and-templates-are-kep was merged into main as bb4f864.

Review

Sign in to review this change.
2 files changed +22 −4
src/http/edge_cache.ts +4 −3
@@ -23,11 +23,12 @@ export type IsPublicRepo = (owner: string, name: string) => boolean;
2323
2424 /**
2525 * 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.
2829 */
2930 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;
3132 const m = /^\/([^/]+)\/([^/]+)$/.exec(pathname);
3233 return m !== null && isPublicRepo(m[1]!, m[2]!);
3334 }
test/web-budget.test.ts +18 −1
@@ -5,7 +5,7 @@ import { tmpdir } from "node:os";
55 import { join } from "node:path";
66 import { createApp, type App } from "../src/app.ts";
77 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";
99 import { commitToBranch, createLabel, createRepo } from "../src/actions/repos.ts";
1010 import { NO_PREFETCH_PATHS, NO_PREFETCH_QUERY, pageScriptAsset, pageScriptDir, pageScriptNamed, speculationAsset } from "../src/web/asset.ts";
1111 import { rawResponse } from "../src/web/pages/repo.ts";
@@ -105,6 +105,23 @@ describe("web budgets (docs/web.md)", () => {
105105 expect(sharedCache(new Request("http://x/"), "/ada/engine/issues", () => false)).toBe("no-cache");
106106 });
107107
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
108125 test("back/forward cache: no no-store, no unload handlers", async () => {
109126 for (const init of [{}, { headers: { cookie } }]) {
110127 const res = await fetch(base + "/", init);

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs