kataras/iris · warning
ErrNotSupportedCompression
ErrNotSupportedCompression
Error message
%w: %s
What it means
compress.Writer.GetEncoding returns ErrNotSupportedCompression wrapped with the empty/failed encoding when the Accept-Encoding negotiation finds no usable offer. negotiateAcceptHeader scans the client's Accept-Encoding header against the offers and falls back to IDENTITY; if even that match yields an empty string, the error is returned. It is reached from AcquireCompressResponseWriter in the middleware chain.
Source
Thrown at context/compress.go:58
// 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)
}
return encoding, nil
}
type (
noOpWriter struct{}
noOpReadCloser struct {
io.Reader
}
)
var (
_ io.ReadCloser = (*noOpReadCloser)(nil)
_ io.Writer = (*noOpWriter)(nil)
)
View on GitHub (pinned to 7bedaf55a0)
Solutions
- Inspect the client's Accept-Encoding header and confirm at least one encoding matches the middleware offers (gzip, deflate, br, snappy, s2).
- Check errors.Is(err, compress.ErrNotSupportedCompression) and fall through to serving the response uncompressed instead of failing the request.
- Adjust middleware offers to include the encodings your real clients send, or ensure IDENTITY is an accepted fallback.
- If a proxy strips or rewrites Accept-Encoding, fix the proxy config or normalize the header server-side.
Example fix
// before
err := w.GetEncoding(header.Get("Accept-Encoding")) // returns ErrNotSupportedCompression
// after
encoding, err := w.GetEncoding(header.Get("Accept-Encoding"))
if errors.Is(err, compress.ErrNotSupportedCompression) {
// serve identity (uncompressed) response
next.ServeHTTP(w, r)
return
} Defensive patterns
Strategy: fallback
Validate before calling
ae := r.Header.Get("Accept-Encoding")
if ae != "" && !strings.Contains(ae, "gzip") && !strings.Contains(ae, "deflate") && !strings.Contains(ae, "br") {
// client accepts no offered encoding; skip compress middleware
} Try / catch
encoding, err := w.GetEncoding(acceptEncoding)
if err != nil {
if errors.Is(err, compress.ErrNotSupportedCompression) {
return "", err // caller should serve identity/uncompressed
}
return "", err
} Prevention
- Always include gzip in middleware offers; it is universally supported
- Never send 'identity;q=0' style headers from proxies in front of Iris
- Treat ErrNotSupportedCompression as expected and fall back to uncompressed responses
- Test behind real proxies that may rewrite Accept-Encoding headers
When it happens
Trigger: Calling GetEncoding (via AcquireCompressResponseWriter / the compress middleware) when the client's Accept-Encoding header values cannot be matched to the configured offers and identity negotiation fails. Note the returned 'encoding' interpolated in the message is empty at this point.
Common situations: Exotic or malformed Accept-Encoding headers from proxies, crawlers, or API clients; middleware configured with offers that exclude all client-accepted encodings; version changes where IDENTITY fallback stopped matching a 'identity;q=0' style header.
Related errors
- compress: response will not be compressed
- compress: request is not compressed
- compress: unsupported compression
- empty form field
- precondition failed
AI-assisted analysis of kataras/iris@7bedaf55a0 (2026-08-30).
Data as JSON: /api/errors/fc8f19d5c148e793.
Report an issue: GitHub.