{"record":{"id":"546dab5b2c003d36","repo":"OpenFeign/feign","slug":"unable-to-deflate-request-body","errorCode":null,"errorMessage":"Unable to deflate request body","messagePattern":"Unable to deflate request body","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"hc5/src/main/java/feign/hc5/AsyncApacheHttp5Client.java","lineNumber":185,"sourceCode":"  private static byte[] gzip(byte[] data) {\n    try (ByteArrayOutputStream baos = new ByteArrayOutputStream();\n        GZIPOutputStream gzip = new GZIPOutputStream(baos)) {\n      gzip.write(data);\n      gzip.finish();\n      return baos.toByteArray();\n    } catch (IOException e) {\n      throw new IllegalStateException(\"Unable to gzip request body\", e);\n    }\n  }\n\n  private static byte[] deflate(byte[] data) {\n    try (ByteArrayOutputStream baos = new ByteArrayOutputStream();\n        DeflaterOutputStream deflater = new DeflaterOutputStream(baos)) {\n      deflater.write(data);\n      deflater.finish();\n      return baos.toByteArray();\n    } catch (IOException e) {\n      throw new IllegalStateException(\"Unable to deflate request body\", e);\n    }\n  }\n\n  private ContentType getContentType(Request request) {\n    ContentType contentType = null;\n    for (final Map.Entry<String, Collection<String>> entry : request.headers().entrySet()) {\n      if (entry.getKey().equalsIgnoreCase(\"Content-Type\")) {\n        final Collection<String> values = entry.getValue();\n        if (values != null && !values.isEmpty()) {\n          contentType = ContentType.parse(values.iterator().next());\n          if (contentType.getCharset() == null) {\n            contentType = contentType.withCharset(request.charset());\n          }\n          break;\n        }\n      }\n    }\n    return contentType;","sourceCodeStart":167,"sourceCodeEnd":203,"githubUrl":"https://github.com/OpenFeign/feign/blob/e2a1e27560a1e68840c34f031afca88b36096e30/hc5/src/main/java/feign/hc5/AsyncApacheHttp5Client.java#L167-L203","documentation":"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.","triggerScenarios":"Request carries Content-Encoding: deflate and toClassicHttpRequest calls deflate(body); DeflaterOutputStream.write/finish throws IOException (typically memory exhaustion while buffering the compressed output).","commonSituations":"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.","solutions":["Check the cause chain for OutOfMemoryError or stream errors; increase heap or reduce the payload.","Confirm the server actually accepts Content-Encoding: deflate; remove or correct the header if not.","Retry the request; failures here are usually transient resource issues.","Use a streaming compression approach for large bodies instead of full in-memory buffering."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// before the call\nif (!serverAcceptsDeflate) {\n  throw new IllegalStateException(\"Do not send Content-Encoding: deflate\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  response = client.execute(request, options);\n} catch (IllegalStateException e) {\n  if (e.getMessage().contains(\"Unable to deflate\")) {\n    logger.warn(\"deflate failed, retrying uncompressed\", e);\n    response = client.execute(stripContentEncoding(request), options);\n  } else throw e;\n}","preventionTips":["Verify server-side compression support before enabling deflate","Prefer gzip unless deflate is mandated","Bound request payload sizes"],"tags":["deflate","request-body","http-client","io"],"backgroundTag":"compression-failed","analyzedSha":"e2a1e27560a1e68840c34f031afca88b36096e30","analyzedAt":"2026-09-10T12:37:37.238Z","contentChangedAt":"2026-09-10T12:37:37.238Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}