Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 119a90a

Browse files
committed
Return immutable headers Response from Cache#match, closes #365
1 parent 9365919 commit 119a90a

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

packages/cache/src/cache.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
Request,
44
RequestInfo,
55
Response,
6+
withImmutableHeaders,
67
withStringFormDataFiles,
78
} from "@miniflare/core";
89
import {
@@ -226,7 +227,7 @@ export class Cache implements CacheInterface {
226227
headers,
227228
});
228229
if (!this.#formDataFiles) res = withStringFormDataFiles(res);
229-
return res;
230+
return withImmutableHeaders(res);
230231
}
231232

232233
async delete(

packages/cache/test/cache.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,16 @@ test("Cache: match throws if attempting to load cached response created with Min
238238
"load cached data created with Miniflare 1 and must delete it.",
239239
});
240240
});
241+
test("Cache: match returns Response with immutable headers", async (t) => {
242+
// https://github.com/cloudflare/miniflare/issues/365
243+
const { cache } = t.context;
244+
await cache.put("http://localhost:8787/", testResponse());
245+
const cached = await cache.match("http://localhost:8787/");
246+
t.throws(() => cached?.headers.set("X-Key", "value"), {
247+
instanceOf: TypeError,
248+
message: "immutable",
249+
});
250+
});
241251

242252
const deleteMacro: Macro<[RequestInfo], Context> = async (t, req) => {
243253
const { storage, cache } = t.context;

0 commit comments

Comments
 (0)