kataras/iris · info
compress: request is not compressed
Error message
compress: request is not compressed
What it means
ErrRequestNotCompressed is returned by NewCompressReader when an incoming request is not actually compressed. The caller attempted to create a decompression reader for the request body, but the request's Content-Encoding header indicates no compression. It is a sentinel used to fall back to reading the body as-is.
Source
Thrown at context/compress.go:36
const (
GZIP = "gzip"
DEFLATE = "deflate"
BROTLI = "br"
SNAPPY = "snappy"
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
}View on GitHub (pinned to 7bedaf55a0)
Solutions
- Check the request's Content-Encoding header before creating the reader and only call NewCompressReader when it names a supported encoding.
- Handle the sentinel with errors.Is(err, iris.ErrRequestNotCompressed) and read the body uncompressed (ctx.Request().Body).
- Fix the sending client to set Content-Encoding (e.g. Content-Encoding: gzip) when it actually compresses the body.
- Verify no proxy/load balancer is stripping Content-Encoding from incoming requests.
Example fix
// before
r, err := ctx.DecompressReader()
if err != nil { ctx.StopWithStatus(500); return }
// after
r, err := ctx.DecompressReader()
if err != nil {
if errors.Is(err, iris.ErrRequestNotCompressed) {
r = ctx.Request().Body // read uncompressed body as-is
} else {
ctx.StopWithStatus(500)
return
}
} Defensive patterns
Strategy: fallback
Validate before calling
contentEncoding := ctx.GetHeader("Content-Encoding")
if contentEncoding == "" || contentEncoding == "identity" {
// request body is not compressed; read it directly
} Type guard
func isCompressedRequest(r *http.Request) bool {
ce := r.Header.Get("Content-Encoding")
return ce != "" && ce != "identity"
} Try / catch
r, err := ctx.DecompressReader()
if err != nil {
if errors.Is(err, iris.ErrRequestNotCompressed) {
r = ctx.Request().Body // read body uncompressed
} else {
ctx.StopWithStatus(iris.StatusInternalServerError)
return
}
} Prevention
- Only wrap the request body in a decompress reader when Content-Encoding names a supported algorithm.
- Configure clients to always send Content-Encoding when they compress request bodies.
- Check proxies/load balancers that may strip Content-Encoding from requests.
- Use errors.Is against the sentinel instead of string-matching the message.
When it happens
Trigger: Calling NewCompressReader (e.g. via ctx.DecompressReader or compression middleware reading the body) when the request's Content-Encoding header is missing, empty, or set to "identity".
Common situations: A client uploads an uncompressed body while the server unconditionally wraps the body in a decompress reader; misconfigured API clients that forget Content-Encoding: gzip; load balancers or proxies that decompress request bodies upstream and strip the Content-Encoding header.
Related errors
- compress: response will not be compressed
- compress: unsupported compression
- ErrNotSupportedCompression
- empty form
- empty form field
AI-assisted analysis of kataras/iris@7bedaf55a0 (2026-08-30).
Data as JSON: /api/errors/f8943c829609894b.
Report an issue: GitHub.