denoland/deno · error · TypeError

Response status must not be 206

Error message

Response status must not be 206

What it means

Step 6 of Cache.put(): a 206 Partial Content response must not be cached, because a later cache match would serve an arbitrary byte range instead of the full representation.

Source

Thrown at ext/cache/01_cache.js:160

    } 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 '*'");
        }
      }
    }

    // Step 8.
    if (innerResponse.body !== null && innerResponse.body.unusable()) {
      throw new TypeError("Response body is already used");
    }

View on GitHub (pinned to 89f33cbef2)

Solutions

  1. Do not send a Range header on requests whose responses you intend to cache — fetch the full body.
  2. Skip put() when response.status === 206.

Example fix

// before
await cache.put(req, res); // res.status === 206
// after
if (res.status !== 206) {
  await cache.put(req, res);
}
Defensive patterns

Strategy: validation

Validate before calling

if (response.status !== 206) {
  await cache.put(request, response);
}

Try / catch

try { await cache.put(req, res); } catch (e) { if (e instanceof TypeError) { /* partial content: not cacheable */ } else throw e; }

Prevention

When it happens

Trigger: Caching a response produced from a Range request (response.status === 206).

Common situations: Media players, resumable downloaders, and range-streaming clients that also try to populate the Cache API.

Related errors


AI-assisted analysis of denoland/deno@89f33cbef2 (2026-08-16). Data as JSON: /api/errors/acfdc6887483b66c. Report an issue: GitHub.