Skip to content

Commit

Permalink
Fix cache tests following #515's preserving URL change (#523)
Browse files Browse the repository at this point in the history
Similar to #475, we weren't deleting the `MF-Original-URL` header
from incoming requests, leading to incorrect URLs in the loopback
server when the incoming request was passed-through as the cache key.

Tests also needed to be updated as the storage location is now based
off the actual URL passed to `dispatchFetch()`.
  • Loading branch information
mrbbot committed Oct 31, 2023
1 parent 9aea1c7 commit 1c545c7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/miniflare/src/plugins/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ export const SCRIPT_ENTRY = `async function handleEvent(event) {
redirect: event.request.redirect,
body: event.request.body,
});
request.headers.delete("${HEADER_ORIGINAL_URL}");
if (globalThis.${BINDING_SERVICE_USER} === undefined) {
return new Response("No entrypoint worker found", { status: 404 });
Expand Down
5 changes: 2 additions & 3 deletions packages/miniflare/test/plugins/cache/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,15 +373,14 @@ test.serial("operations persist cached data", async (t) => {
t.teardown(() => t.context.setOptions({}));

const key = "http://localhost/cache-persist";
const storedKey = new URL("/cache-persist", t.context.url).toString();

// Check put respects persist
await t.context.mf.dispatchFetch(key, {
method: "PUT",
headers: { "Test-Response-Cache-Control": "max-age=3600" },
body: "body",
});
let stored = await storage.get(storedKey);
let stored = await storage.get(key);
t.deepEqual(stored?.value, utf8Encode("body"));

// Check match respects persist
Expand All @@ -392,7 +391,7 @@ test.serial("operations persist cached data", async (t) => {
// Check delete respects persist
res = await t.context.mf.dispatchFetch(key, { method: "DELETE" });
t.is(res.status, 204);
stored = await storage.get(storedKey);
stored = await storage.get(key);
t.is(stored, undefined);
});
test.serial("operations are no-ops when caching disabled", async (t) => {
Expand Down

0 comments on commit 1c545c7

Please sign in to comment.