kataras/iris · warning

compress: unsupported compression

Error message

compress: unsupported compression

What it means

ErrNotSupportedCompression is returned by GetEncoding, AcquireCompressResponseWriter, NewCompressWriter and NewCompressReader when the encoding named in the client's Accept-Encoding (or the requested encoding) is not among the server's configured/supported algorithms (by default GZIP, DEFLATE, BROTLI, SNAPPY). The docs advise checking it with errors.Is. It indicates a negotiation mismatch between client and server.

Source

Thrown at context/compress.go:41

	S2      = "s2"
)

// IDENTITY no transformation whatsoever.
const IDENTITY = "identity"

var (
	// ErrResponseNotCompressed returned from AcquireCompressResponseWriter
	// when response's Content-Type header is missing due to golang/go/issues/31753 or
	// when accept-encoding is empty. The caller should fallback to the original response writer.
	ErrResponseNotCompressed = errors.New("compress: response will not be compressed")
	// ErrRequestNotCompressed returned from NewCompressReader
	// when request is not compressed.
	ErrRequestNotCompressed = errors.New("compress: request is not compressed")
	// ErrNotSupportedCompression returned from
	// AcquireCompressResponseWriter, NewCompressWriter and NewCompressReader
	// when the request's Accept-Encoding was not found in the server's supported
	// compression algorithms. Check that error with `errors.Is`.
	ErrNotSupportedCompression = errors.New("compress: unsupported compression")
)

// AllEncodings is a slice of default content encodings.
// See `AcquireCompressResponseWriter`.
var AllEncodings = []string{GZIP, DEFLATE, BROTLI, SNAPPY}

// GetEncoding extracts the best available encoding from the request.
func GetEncoding(r *http.Request, offers []string) (string, error) {
	acceptEncoding := r.Header[AcceptEncodingHeaderKey]

	if len(acceptEncoding) == 0 {
		return "", ErrResponseNotCompressed
	}

	encoding := negotiateAcceptHeader(acceptEncoding, offers, IDENTITY)
	if encoding == "" {
		return "", fmt.Errorf("%w: %s", ErrNotSupportedCompression, encoding)
	}

View on GitHub (pinned to 7bedaf55a0)

Solutions

  1. Add the missing algorithm to the server's supported encodings (e.g. compress.New with encodings including the one clients send) or to AllEncodings.
  2. Check with errors.Is(err, iris.ErrNotSupportedCompression) and respond with an identity (uncompressed) response or 406.
  3. Align client Accept-Encoding with the server's supported list (e.g. request only gzip).
  4. Register the matching compressor (e.g. import the brotli/snappy child package) so the algorithm is actually available.

Example fix

// before
enc, err := iris.GetEncoding(ctx.GetHeader("Accept-Encoding")) // zstd -> ErrNotSupportedCompression
// after
clientEnc := ctx.GetHeader("Accept-Encoding")
enc, err := iris.GetEncoding(clientEnc)
if errors.Is(err, iris.ErrNotSupportedCompression) {
    clientEnc = iris.IDENTITY // fall back to no compression
    enc, err = iris.GetEncoding(clientEnc)
}
Defensive patterns

Strategy: validation

Validate before calling

encodings := iris.AllEncodings // GZIP, DEFLATE, BROTLI, SNAPPY
clientEnc := ctx.GetHeader("Accept-Encoding")
for _, e := range encodings {
    if strings.Contains(clientEnc, e) {
        // supported, safe to negotiate
        break
    }
}

Type guard

func isSupportedEncoding(enc string) bool {
    for _, e := range iris.AllEncodings {
        if strings.EqualFold(e, enc) {
            return true
        }
    }
    return false
}

Try / catch

enc, err := iris.GetEncoding(ctx.GetHeader("Accept-Encoding"))
if err != nil {
    if errors.Is(err, iris.ErrNotSupportedCompression) {
        // respond identity/uncompressed or 406 Not Acceptable
    } else {
        ctx.StopWithStatus(iris.StatusInternalServerError)
        return
    }
}

Prevention

When it happens

Trigger: A request advertises Accept-Encoding (or Content-Encoding for readers) with an algorithm not in the server's configured encoding list, e.g. zstd when the server only has gzip/deflate/brotli/snappy; or AcquireCompressResponseWriter is called with an explicit encoding string that is not registered.

Common situations: Clients sending modern encodings like zstd or br when the server was configured with only gzip; custom AllEncodings/encodings option that omits an algorithm a client requests; version changes where a previously available algorithm is not configured; typo in a custom encoding string.

Related errors


AI-assisted analysis of kataras/iris@7bedaf55a0 (2026-08-30). Data as JSON: /api/errors/aca90f911651a9ea. Report an issue: GitHub.