{"record":{"id":"2b9b24afd1d5a308","repo":"valyala/fasthttp","slug":"fasthttp-unsupported-content-encoding","errorCode":null,"errorMessage":"fasthttp: unsupported content-encoding","messagePattern":"fasthttp: unsupported content-encoding","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"http.go","lineNumber":684,"sourceCode":"func unzstdData(p []byte, maxBodySize int) ([]byte, error) {\n\tvar bb bytebufferpool.ByteBuffer\n\t_, err := writeUnzstd(&bb, p, maxBodySize)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\treturn bb.B, nil\n}\n\nfunc inflateData(p []byte, maxBodySize int) ([]byte, error) {\n\tvar bb bytebufferpool.ByteBuffer\n\t_, err := writeInflate(&bb, p, maxBodySize)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\treturn bb.B, nil\n}\n\nvar ErrContentEncodingUnsupported = errors.New(\"fasthttp: unsupported content-encoding\")\n\n// BodyUncompressed returns body data and if needed decompresses it from gzip,\n// deflate, brotli or zstd.\n//\n// This method may be used if the response header contains\n// 'Content-Encoding' for reading uncompressed request body.\n// Use Body for reading the raw request body.\nfunc (req *Request) BodyUncompressed() ([]byte, error) {\n\treturn req.BodyUncompressedWithLimit(0)\n}\n\n// BodyUncompressedWithLimit returns body data and if needed decompresses it from gzip,\n// deflate, brotli or zstd. The size of uncompressed data is limited to maxBodySize bytes.\n//\n// If maxBodySize <= 0, then no limit is applied.\nfunc (req *Request) BodyUncompressedWithLimit(maxBodySize int) ([]byte, error) {\n\tswitch string(req.Header.ContentEncoding()) {\n\tcase \"\":","sourceCodeStart":666,"sourceCodeEnd":702,"githubUrl":"https://github.com/valyala/fasthttp/blob/c96f600972c6f4a7a30d664257b340ebe9d60124/http.go#L666-L702","documentation":"Response.BodyUncompressed() decompresses the body only for gzip, deflate, brotli and zstd Content-Encoding values. If the response carries a different (or unknown) content-encoding, fasthttp returns ErrContentEncodingUnsupported instead of guessing.","triggerScenarios":"Calling Response.BodyUncompressed() (or equivalent body decode paths) on a response whose Content-Encoding header is not gzip/deflate/br/zstd — e.g. 'compress', a custom encoding, or double-encoded values.","commonSituations":"Proxies adding unusual encodings; servers sending 'identity' variants or vendor encodings; accidentally requesting encodings via Accept-Encoding that fasthttp can't decode.","solutions":["Check resp.Header.ContentEncoding() and fall back to resp.Body() (raw) when it isn't one of the supported encodings.","Only send supported Accept-Encoding values from the client so the server negotiates a decodable encoding.","Configure the upstream/proxy to use gzip or identity.","Decode manually with a third-party package if you truly need the exotic encoding."],"exampleFix":"// before\nbody := resp.BodyUncompressed()\n// after\nvar body []byte\nswitch resp.Header.ContentEncoding() {\ncase \"gzip\", \"deflate\", \"br\", \"zstd\":\n    body = resp.BodyUncompressed()\ndefault:\n    body = resp.Body()\n}","handlingStrategy":"fallback","validationCode":"enc := string(resp.Header.ContentEncoding())\nsupported := enc == \"\" || enc == \"gzip\" || enc == \"deflate\" || enc == \"br\" || enc == \"zstd\"","typeGuard":null,"tryCatchPattern":"body, err := safeBody(resp)\nfunc safeBody(resp *fasthttp.Response) ([]byte, error) {\n    if err := errUnsupportedEnc(resp); err != nil { return resp.Body(), nil }\n    return resp.BodyUncompressed(), nil\n}","preventionTips":["Only advertise Accept-Encoding values fasthttp can decode","Check Content-Encoding before calling BodyUncompressed","Normalize upstream encodings to gzip at the proxy"],"tags":["http","compression","content-encoding","fasthttp"],"backgroundTag":"unsupported-content-encoding","analyzedSha":"c96f600972c6f4a7a30d664257b340ebe9d60124","analyzedAt":"2026-08-31T22:48:28.265Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}