cloudflare / cloudflare/workers-sdk

Miniflare cache refuses to store different status codes than the production environment

Open
#9,040 2 comments 0 reactions 0 assignees View on GitHub
package:miniflare
Dominant language
TypeScript
Stars
4.5k
Forks
1.5k
Avg merge
3d 8h
Merged PRs (30d)
187

Description

### Which Cloudflare product(s) does this pertain to?

Miniflare

### What versions & operating system are you using?

Wrangler v4.13.0

### Please provide a link to a minimal reproduction

_No response_

### Describe the Bug

Here’s the MWE:

```ts
export default {
async fetch() {
await caches.default.put(
"https://cloudflare.com",
Response.json("OK", {
status: 201,
headers: {
"Cache-Control": "public",
},
}),
);
const cachedResponse = await caches.default.match("https://cloudflare.com");
return Response.json(cachedResponse !== undefined);
},
} satisfies ExportedHandler;
```

In local dev, this returns `false`. In prod, it returns `true`. This is because Miniflare uses `http-cache-semantics` to determine if a response is storable:

https://github.com/cloudflare/workers-sdk/blob/a9190de1340dfe43c38fec729e01139f499351dd/packages/miniflare/src/workers/cache/cache.worker.ts#L341-L353

But Cloudflare’s cache accepts different status codes to `http-cache-semantics`. (I’d submit a PR to patch over this behaviour in the `if(!storable)` check, but I couldn’t easily find which status codes Cloudflare’s cache accepts—if someone can point me to those I’ll do it. I _think_ the only code the cache will reject is a `206`?)

I can get this to work for my use case by overriding the status code from a `201` to a `200`, but I figured it’s worth having a record that this bug exists.

### Please provide any relevant error logs

_No response_

Contributor guide

Open the contributing guide

Research direction

Read packages/miniflare/src/workers/cache/cache.worker.ts around lines 341-353 and inspect how http-cache-semantics decides whether a response is storable. Reproduce the provided Wrangler v4.13.0 example, then determine which status codes Cloudflare accepts before changing the local behavior. Done means supported production status codes are retrievable through caches.default.match while unsupported responses remain rejected.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.