denoland/deno · error · TypeError
Request method must be GET
Error message
Request method must be GET
What it means
Cache.put(request, response) only accepts GET requests: after the URL protocol check, the implementation rejects any request whose method is not GET. This mirrors the spec rule that only GET requests can be stored in the HTTP cache.
Solutions
- Construct the cache key as a GET request: `cache.put(new Request(url), res)`
- Store POST/PUT responses in your own storage (KV, IndexedDB) rather than the Cache API
- Check `request.method === "GET"` before calling cache.put when the Request comes from elsewhere
Example fix
// before
await cache.put(new Request(url, { method: "POST" }), res);
// after
await cache.put(new Request(url), res); // GET key; body lives in res Defensive patterns
Strategy: validation
Validate before calling
if (request.method !== "GET") {
// store POST/PUT results elsewhere; only GET is cacheable
} Prevention
- Build cache keys with new Request(url) (defaults to GET)
- Check request.method before cache.put when the Request comes from elsewhere
- Keep a separate storage path for non-GET API results
When it happens
Trigger: `cache.put(new Request(url, { method: "POST" }), res)`; reusing a Request object previously created with method PUT/PATCH/HEAD/DELETE and passing it to cache.put.
Common situations: Caching API POST results for offline mode; accidentally reusing a mutated Request; porting code from a generic cache that accepted any method.
Related errors
- ERR_INVALID_ARG_VALUE
- Method is not valid
- Request url protocol must be 'http:' or 'https:': received
- Vary header must not contain '*'
- "autoAllocateChunkSize" must be greater than 0
AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20).
Data as JSON: /api/errors/78dc6d3892c6c0c7.
Report an issue: GitHub.
Appendix: source
Thrown at ext/cache/01_cache.js:154
response = webidl.converters["Response"](response, prefix, "Argument 2");
// Step 1.
let innerRequest = null;
// Step 2.
if (ObjectPrototypeIsPrototypeOf(RequestPrototype, request)) {
innerRequest = toInnerRequest(request);
} else {
// Step 3.
innerRequest = toInnerRequest(new Request(request));
}
// Step 4.
const reqUrl = new URL(innerRequest.url());
if (reqUrl.protocol !== "http:" && reqUrl.protocol !== "https:") {
throw new TypeError(
`Request url protocol must be 'http:' or 'https:': received '${reqUrl.protocol}'`,
);
}
if (innerRequest.method !== "GET") {
throw new TypeError("Request method must be GET");
}
// Step 5.
const innerResponse = toInnerResponse(response);
// Step 6.
if (innerResponse.status === 206) {
throw new TypeError("Response status must not be 206");
}
// Step 7.
const varyHeader = getHeader(innerResponse.headerList, "vary");
if (varyHeader) {
const fieldValues = StringPrototypeSplit(varyHeader, ",");
for (let i = 0; i < fieldValues.length; ++i) {
const field = fieldValues[i];
if (StringPrototypeTrim(field) === "*") {
throw new TypeError("Vary header must not contain '*'");
}
}
}View on GitHub (pinned to 9ad36f7a2c)