denoland/deno · error · TypeError
Vary header must not contain '*'
Error message
Vary header must not contain '*'
What it means
Cache.put(request, response) parses the response's Vary header (spec step 7) and rejects the operation if any field value is '*'. Vary: * means the response depends on unspecified request headers, making it uncacheable by design.
Solutions
- Check `response.headers.get("vary")` for a '*' entry before calling cache.put and skip caching
- If you control the origin, send a concrete Vary list (e.g. 'Accept-Encoding') instead of '*'
- Store such responses outside the Cache API if you really need them
Example fix
// before
await cache.put(req, res); // res has Vary: *
// after
const vary = (res.headers.get("vary") ?? "").split(",").map((s) => s.trim());
if (!vary.includes("*")) await cache.put(req, res); Defensive patterns
Strategy: validation
Validate before calling
function hasVaryWildcard(res: Response): boolean {
return (res.headers.get("vary") ?? "")
.split(",")
.some((f) => f.trim() === "*");
} Prevention
- Inspect the Vary header before cache.put
- Fix origins you control to send concrete Vary lists
- Treat Vary: * responses as explicitly uncacheable
When it happens
Trigger: The origin returns `Vary: *` (or `Vary: Accept, *`) and the code calls cache.put with that response; the check splits the header on commas and trims each field before comparing to '*'.
Common situations: Caching third-party API responses where the origin sets Vary: * to defeat shared caches; CDNs that aggregate Vary values.
Related errors
- Request method must be GET
- Request url protocol must be 'http:' or 'https:': received
- "autoAllocateChunkSize" must be greater than 0
- BenchContext::start() has already been invoked
- Body already consumed.
AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20).
Data as JSON: /api/errors/4f4cbf1d9ac598d6.
Report an issue: GitHub.
Appendix: source
Thrown at ext/cache/01_cache.js:169
);
}
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 '*'");
}
}
}
// Step 8.
if (innerResponse.body !== null && innerResponse.body.unusable()) {
throw new TypeError("Response body is already used");
}
const stream = innerResponse.body?.stream;
let rid = null;
if (stream) {
const resourceBacking = getReadableStreamResourceBacking(
innerResponse.body?.stream,
);
if (resourceBacking) {
rid = resourceBacking.rid;
} else {View on GitHub (pinned to 9ad36f7a2c)