{"record":{"id":"9a6fbb6be1beed20","repo":"d2lang/d2","slug":"unsupported-content-encoding-q","errorCode":null,"errorMessage":"unsupported content encoding %q","messagePattern":"unsupported content encoding %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/imgbundler/imgbundler.go","lineNumber":270,"sourceCode":"\nfunc decodeContentEncoding(buf []byte, contentEncoding string) ([]byte, error) {\n\tencodings := strings.Split(contentEncoding, \",\")\n\tfor i := len(encodings) - 1; i >= 0; i-- {\n\t\tencoding := strings.TrimSpace(strings.ToLower(encodings[i]))\n\t\tif encoding == \"\" || encoding == \"identity\" {\n\t\t\tcontinue\n\t\t}\n\n\t\tvar err error\n\t\tswitch encoding {\n\t\tcase \"gzip\", \"x-gzip\":\n\t\t\tbuf, err = gunzip(buf)\n\t\tcase \"br\":\n\t\t\tbuf, err = readDecoded(brotli.NewReader(bytes.NewReader(buf)))\n\t\tcase \"deflate\":\n\t\t\tbuf, err = inflate(buf)\n\t\tdefault:\n\t\t\treturn nil, fmt.Errorf(\"unsupported content encoding %q\", encoding)\n\t\t}\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t}\n\treturn buf, nil\n}\n\nfunc gunzip(buf []byte) ([]byte, error) {\n\tr, err := gzip.NewReader(bytes.NewReader(buf))\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tdefer r.Close()\n\treturn readDecoded(r)\n}\n\nfunc inflate(buf []byte) ([]byte, error) {","sourceCodeStart":252,"sourceCodeEnd":288,"githubUrl":"https://github.com/d2lang/d2/blob/0d69dca6f532ceaeacd615d35d1eaa41a238ffdb/lib/imgbundler/imgbundler.go#L252-L288","documentation":"decodeContentEncoding supports only gzip, br (brotli), and deflate. Any other Content-Encoding value (or an unrecognized token) hits the default branch and returns this error. The bundler cannot decode the response body, so the image fetch fails.","triggerScenarios":"Server advertises an encoding outside the supported set — e.g. zstd, compress, or a nonstandard token like 'x-gzip' — in the Content-Encoding header of an image response.","commonSituations":"Modern origins negotiating zstd (supported by browsers but not this client), proxies injecting 'compress', or misconfigured servers emitting unusual encoding tokens.","solutions":["Configure the origin/CDN to serve gzip, br, or deflate (or identity) for images — images rarely need zstd","Strip Accept-Encoding for zstd in any client/transport config you control so the server falls back to a supported encoding","If you control the library, add a case for the encoding (e.g. zstd) in decodeContentEncoding","Work around by fetching the asset without compression (Accept-Encoding: identity)"],"exampleFix":"// before\nreq.Header.Set(\"Accept-Encoding\", \"gzip, deflate, br, zstd\")\n// after\nreq.Header.Set(\"Accept-Encoding\", \"gzip, deflate, br\")","handlingStrategy":"validation","validationCode":"allowed := map[string]bool{\"gzip\": true, \"br\": true, \"deflate\": true, \"\": true}\nreq.Header.Set(\"Accept-Encoding\", \"gzip, deflate, br\") // never advertise zstd/compress","typeGuard":null,"tryCatchPattern":"if _, _, err := httpGet(ctx, client, href); err != nil {\n\tif strings.Contains(err.Error(), \"unsupported content encoding\") {\n\t\t// refetch with Accept-Encoding: identity\n\t}\n}","preventionTips":["Only advertise Accept-Encoding values your decoder supports","Configure origins/CDNs to serve images with gzip/br/deflate or identity","Disable zstd negotiation in any shared HTTP client config","Fail fast in integration tests when a new Content-Encoding appears"],"tags":["http","compression","content-encoding","go"],"backgroundTag":"unsupported-content-encoding","analyzedSha":"0d69dca6f532ceaeacd615d35d1eaa41a238ffdb","analyzedAt":"2026-08-31T12:19:21.182Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}