valyala/fasthttp · error

fasthttp: unsupported content-encoding

Error message

fasthttp: unsupported content-encoding

What it means

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.

Source

Thrown at http.go:684

func unzstdData(p []byte, maxBodySize int) ([]byte, error) {
	var bb bytebufferpool.ByteBuffer
	_, err := writeUnzstd(&bb, p, maxBodySize)
	if err != nil {
		return nil, err
	}
	return bb.B, nil
}

func inflateData(p []byte, maxBodySize int) ([]byte, error) {
	var bb bytebufferpool.ByteBuffer
	_, err := writeInflate(&bb, p, maxBodySize)
	if err != nil {
		return nil, err
	}
	return bb.B, nil
}

var ErrContentEncodingUnsupported = errors.New("fasthttp: unsupported content-encoding")

// BodyUncompressed returns body data and if needed decompresses it from gzip,
// deflate, brotli or zstd.
//
// This method may be used if the response header contains
// 'Content-Encoding' for reading uncompressed request body.
// Use Body for reading the raw request body.
func (req *Request) BodyUncompressed() ([]byte, error) {
	return req.BodyUncompressedWithLimit(0)
}

// BodyUncompressedWithLimit returns body data and if needed decompresses it from gzip,
// deflate, brotli or zstd. The size of uncompressed data is limited to maxBodySize bytes.
//
// If maxBodySize <= 0, then no limit is applied.
func (req *Request) BodyUncompressedWithLimit(maxBodySize int) ([]byte, error) {
	switch string(req.Header.ContentEncoding()) {
	case "":

View on GitHub (pinned to c96f600972)

Solutions

  1. Check resp.Header.ContentEncoding() and fall back to resp.Body() (raw) when it isn't one of the supported encodings.
  2. Only send supported Accept-Encoding values from the client so the server negotiates a decodable encoding.
  3. Configure the upstream/proxy to use gzip or identity.
  4. Decode manually with a third-party package if you truly need the exotic encoding.

Example fix

// before
body := resp.BodyUncompressed()
// after
var body []byte
switch resp.Header.ContentEncoding() {
case "gzip", "deflate", "br", "zstd":
    body = resp.BodyUncompressed()
default:
    body = resp.Body()
}
Defensive patterns

Strategy: fallback

Validate before calling

enc := string(resp.Header.ContentEncoding())
supported := enc == "" || enc == "gzip" || enc == "deflate" || enc == "br" || enc == "zstd"

Try / catch

body, err := safeBody(resp)
func safeBody(resp *fasthttp.Response) ([]byte, error) {
    if err := errUnsupportedEnc(resp); err != nil { return resp.Body(), nil }
    return resp.BodyUncompressed(), nil
}

Prevention

When it happens

Trigger: 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.

Common situations: Proxies adding unusual encodings; servers sending 'identity' variants or vendor encodings; accidentally requesting encodings via Accept-Encoding that fasthttp can't decode.

Related errors


AI-assisted analysis of valyala/fasthttp@c96f600972 (2026-08-31). Data as JSON: /api/errors/2b9b24afd1d5a308. Report an issue: GitHub.