OpenFeign/feign · error · IllegalStateException

Unable to deflate request body

Error message

Unable to deflate request body

What it means

Thrown by AsyncApacheHttp5Client's deflate helper when DEFLATE-compressing the request body via DeflaterOutputStream raises an IOException. Like the gzip path, in-memory deflate almost never fails; the wrapper converts the IOException into IllegalStateException to abort request construction with a descriptive message.

Solutions

  1. Check the cause chain for OutOfMemoryError or stream errors; increase heap or reduce the payload.
  2. Confirm the server actually accepts Content-Encoding: deflate; remove or correct the header if not.
  3. Retry the request; failures here are usually transient resource issues.
  4. Use a streaming compression approach for large bodies instead of full in-memory buffering.
Defensive patterns

Strategy: try-catch

Validate before calling

// before the call
if (!serverAcceptsDeflate) {
  throw new IllegalStateException("Do not send Content-Encoding: deflate");
}

Try / catch

try {
  response = client.execute(request, options);
} catch (IllegalStateException e) {
  if (e.getMessage().contains("Unable to deflate")) {
    logger.warn("deflate failed, retrying uncompressed", e);
    response = client.execute(stripContentEncoding(request), options);
  } else throw e;
}

Prevention

When it happens

Trigger: Request carries Content-Encoding: deflate and toClassicHttpRequest calls deflate(body); DeflaterOutputStream.write/finish throws IOException (typically memory exhaustion while buffering the compressed output).

Common situations: Large request bodies on memory-constrained JVMs/containers; misconfigured Content-Encoding header (server expects gzip but client set deflate, causing confusion while debugging); service mesh or proxy requiring specific compression schemes.

Related errors


AI-assisted analysis of OpenFeign/feign@e2a1e27560 (2026-09-10). Data as JSON: /api/errors/546dab5b2c003d36. Report an issue: GitHub.

Appendix: source

Thrown at hc5/src/main/java/feign/hc5/AsyncApacheHttp5Client.java:185

  private static byte[] gzip(byte[] data) {
    try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
        GZIPOutputStream gzip = new GZIPOutputStream(baos)) {
      gzip.write(data);
      gzip.finish();
      return baos.toByteArray();
    } catch (IOException e) {
      throw new IllegalStateException("Unable to gzip request body", e);
    }
  }

  private static byte[] deflate(byte[] data) {
    try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
        DeflaterOutputStream deflater = new DeflaterOutputStream(baos)) {
      deflater.write(data);
      deflater.finish();
      return baos.toByteArray();
    } catch (IOException e) {
      throw new IllegalStateException("Unable to deflate request body", e);
    }
  }

  private ContentType getContentType(Request request) {
    ContentType contentType = null;
    for (final Map.Entry<String, Collection<String>> entry : request.headers().entrySet()) {
      if (entry.getKey().equalsIgnoreCase("Content-Type")) {
        final Collection<String> values = entry.getValue();
        if (values != null && !values.isEmpty()) {
          contentType = ContentType.parse(values.iterator().next());
          if (contentType.getCharset() == null) {
            contentType = contentType.withCharset(request.charset());
          }
          break;
        }
      }
    }
    return contentType;

View on GitHub (pinned to e2a1e27560)