kataras/iris · info

compress: response will not be compressed

Error message

compress: response will not be compressed

What it means

ErrResponseNotCompressed is returned by AcquireCompressResponseWriter (surfaced via GetEncoding) when Iris decides the response cannot or should not be compressed. This happens when the response's Content-Type header is missing (a known Go issue golang/go#31753) or when the client's Accept-Encoding header is empty. It is a sentinel signal for the caller to fall back to the original, uncompressed response writer rather than a failure.

Source

Thrown at context/compress.go:33

)

// The available builtin compression algorithms.
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]

View on GitHub (pinned to 7bedaf55a0)

Solutions

  1. Ensure the client sends an Accept-Encoding header (e.g. curl --compressed or a browser/fetch client).
  2. Set the response Content-Type explicitly via ctx.ContentType("text/html") or similar before acquiring the compress writer.
  3. Treat the error as expected control flow: use errors.Is(err, iris.ErrResponseNotCompressed) and fall back to writing with the original ResponseWriter.
  4. If using middleware (compress.New), verify it is configured with encodings the client supports.

Example fix

// before
w, err := ctx.CompressWriter(false)
if err != nil { ctx.StopWithStatus(500); return }
// after
w, err := ctx.CompressWriter(false)
if err != nil {
    if errors.Is(err, iris.ErrResponseNotCompressed) {
        // fall back to the original writer, no compression
        ctx.ContentType("text/plain")
        ctx.WriteString("data")
        return
    }
    ctx.StopWithStatus(500)
    return
}
Defensive patterns

Strategy: fallback

Validate before calling

acceptEnc := ctx.GetHeader("Accept-Encoding")
contentType := ctx.GetHeader("Content-Type") // response-side: ensure ctx.ContentType was called
if acceptEnc == "" || contentType == "" {
    // skip compression, use original writer
}

Type guard

func willCompress(acceptEncoding, contentType string) bool {
    return acceptEncoding != "" && contentType != ""
}

Try / catch

w, err := ctx.CompressWriter(false)
if err != nil {
    if errors.Is(err, iris.ErrResponseNotCompressed) {
        // fall back: write uncompressed with the original writer
    } else {
        ctx.StopWithStatus(iris.StatusInternalServerError)
        return
    }
}

Prevention

When it happens

Trigger: Calling AcquireCompressResponseWriter/GetEncoding when (1) the response has no Content-Type header set (Go strips it when WriteHeader has not decided content type, golang/go#31753), or (2) the request's Accept-Encoding header is empty or absent.

Common situations: Client tools like curl without --compressed, or non-HTTP/1.1 clients that omit Accept-Encoding; handlers that write the body before the Content-Type is determined; proxies or middleware that strip Content-Type; apps relying on Go's automatic content-type sniffing without calling ctx.ContentType first.

Related errors


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