Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions study-contact.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ export default {
const asset = await env.ASSETS.fetch(new Request(url, request));
const response = new Response(asset.body, asset);
response.headers.set("Cache-Control", "no-store");
if (url.searchParams.get("reset-cache") === "1") {
// Recover browser-cached redirects without clearing cookies or storage.
response.headers.set("Clear-Site-Data", '"cache"');
}
return response;
}
if (url.pathname === "/api/study-contact") {
Expand Down
10 changes: 10 additions & 0 deletions study-contact.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,16 @@ describe("worker.fetch routing", () => {
expect(requests).toEqual([`${ORIGIN}/`, `${ORIGIN}/study/`, `${ORIGIN}/study/`, "https://seniorstudy.org/study/?ref=flyer"]);
});

it("allows an explicit cache-only recovery without clearing login data", async () => {
const env = { ASSETS: { fetch: async () => new Response("study") } };
const normal = await worker.fetch(new Request(`${ORIGIN}/study`), env);
const recovery = await worker.fetch(new Request(`${ORIGIN}/study?reset-cache=1`), env);
expect(normal.headers.get("clear-site-data")).toBeNull();
expect(recovery.headers.get("clear-site-data")).toBe('"cache"');
expect(recovery.headers.get("cache-control")).toBe("no-store");
expect(await recovery.text()).toBe("study");
});

it("counts multibyte input toward the request size limit", async () => {
const response = await worker.fetch(contactRequest({message: "🧡".repeat(9000)}), SECRETS);
expect(response.status).toBe(413);
Expand Down
Loading