{"record":{"id":"007131edfeae162e","repo":"jsdom/jsdom","slug":"too-many-content-encodings-in-response-parts-le","errorCode":null,"errorMessage":"too many content-encodings in response: ${parts.length}, max is ${maxContentEncodings}","messagePattern":"too many content-encodings in response: (.+?), max is (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/jsdom/browser/resources/decompress-interceptor.js","lineNumber":54,"sourceCode":"  #shouldSkipDecompression(contentEncoding, statusCode) {\n    if (!contentEncoding || statusCode < 200) {\n      return true;\n    }\n    if (this.#skipStatusCodes.includes(statusCode)) {\n      return true;\n    }\n    if (this.#skipErrorResponses && statusCode >= 400) {\n      return true;\n    }\n    return false;\n  }\n\n  #createDecompressionChain(encodings) {\n    const parts = encodings.split(\",\");\n\n    const maxContentEncodings = 5;\n    if (parts.length > maxContentEncodings) {\n      throw new Error(`too many content-encodings in response: ${parts.length}, max is ${maxContentEncodings}`);\n    }\n\n    const decompressors = [];\n\n    for (let i = parts.length - 1; i >= 0; i--) {\n      const encoding = parts[i].trim();\n      if (!encoding) {\n        continue;\n      }\n\n      if (!supportedEncodings[encoding]) {\n        decompressors.length = 0;\n        return decompressors;\n      }\n\n      decompressors.push(supportedEncodings[encoding]());\n    }\n","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/jsdom/jsdom/blob/904cc9cd2464e959b739910cb046afe57f7a1922/lib/jsdom/browser/resources/decompress-interceptor.js#L36-L72","documentation":"The decompress interceptor rejects responses whose `Content-Encoding` header lists more than 5 comma-separated encodings. Each encoding requires a decompression step in a chain, and jsdom caps the chain at `maxContentEncodings = 5` to bound resource use and guard against pathological or malicious responses. Exceeding the cap throws a plain Error naming the count and the maximum.","triggerScenarios":"A server (or intercepted mock) responds with `Content-Encoding: gzip, gzip, gzip, gzip, gzip, gzip` (six or more encodings). The error is thrown from #createDecompressionChain while building the decompressor chain for the response.","commonSituations":"Misconfigured compression middleware that compresses multiple times; proxies stacking encodings; deliberately malicious or fuzzed servers; mocked responses in tests with hand-written Content-Encoding headers.","solutions":["Fix the server/proxy so it sends a single Content-Encoding value (e.g. `gzip`)","Check for double-compression in middleware: the body should be compressed once, not per-hop","If you legitimately need deep stacking, raise `maxContentEncodings` in decompress-interceptor.js and reinstall as a patch","Use undici interceptors to strip duplicate encodings before jsdom's interceptor runs"],"exampleFix":"// before (server response)\nContent-Encoding: gzip, deflate, gzip, br, gzip, deflate\n// after\nContent-Encoding: gzip","handlingStrategy":"validation","validationCode":"function hasSafeContentEncoding(headers, max = 5) {\n  const ce = headers.get('content-encoding') || '';\n  return ce.split(',').filter(Boolean).length <= max;\n}","typeGuard":null,"tryCatchPattern":"try {\n  await loadResource(url);\n} catch (e) {\n  if (e.message.startsWith('too many content-encodings')) {\n    console.error('Server over-compressed response; fix Content-Encoding header', e.message);\n  } else { throw e; }\n}","preventionTips":["Audit server/proxy compression middleware for double-compression","Send at most one Content-Encoding token per response","In tests, never hand-write multi-layer Content-Encoding mock headers","Add integration checks that flag responses with stacked encodings"],"tags":["network","content-encoding","compression","http"],"backgroundTag":"too-many-content-encodings","analyzedSha":"904cc9cd2464e959b739910cb046afe57f7a1922","analyzedAt":"2026-09-01T11:17:47.630Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}