title: Handling gzipped requests in a Spring Boot REST application
body: <p>I have a Spring Boot REST app (1.5.6.RELEASE).  I would like gzip compression incoming and outgoing.  As per this documentation <a href="https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html" rel="noreferrer">https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html</a> I have set</p>
  
  <pre><code>server.compression.enabled=true
  server.compression.mime-types=...
  </code></pre>
  
  <p>But this seems to only apply to gzipping responses from my service (and this is what the doc says actually "# If response compression is enabled.").  </p>
  
  <p>My problem is that incoming gzipped requests are not being decompressed, resulting in JSON parsing errors.</p>
  
  <p>Does anyone know how I can turn on request decompression in my Spring Boot app?</p>
  
  <p><strong>EDIT</strong> An example:</p>
  
  <p>POM snippet:</p>
  
  <pre><code>&lt;parent&gt;
      &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
      &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
      &lt;version&gt;1.5.6.RELEASE&lt;/version&gt;
  &lt;/parent&gt;
  &lt;dependencies&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
      &lt;/dependency&gt;
  &lt;/dependencies&gt;
  </code></pre>
  
  <p>Controller code:</p>
  
  <pre><code>@RestController
  public class Controller {
      @RequestMapping(value = "/", method = RequestMethod.POST, consumes = "application/json")
      public String post(@RequestBody Map&lt;String, String&gt; request) {
          return request.get("key");
     }
  }
  </code></pre>
  
  <p>Test using curl:</p>
  
  <pre><code>$ echo '{ "key":"hello" }' &gt; body
  $ curl -X POST -H "Content-Type: application/json" --data-binary @body http://localhost:8080 # prints 'hello'
  $ echo '{ "key":"hello" }' | gzip &gt; body.gz
  $ curl -X POST -H "Content-Type: application/json" -H "Content-Encoding: gzip" --data-binary @body.gz http://localhost:8080 # fails
  </code></pre>
  
  <p>The gzipped call fails with message:</p>
  
  <pre><code>{"timestamp":1505843443456,"status":400,"error":"Bad Request","exception":"org.springframework.http.converter.HttpMessageNotReadableException","message":"JSON parse error: Illegal character ((CTRL-CHAR, code 31)): only regular white space (\\r, \\n, \\t) is allowed between tokens; nested exception is com.fasterxml.jackson.core.JsonParseException: Illegal character ((CTRL-CHAR, code 31)): only regular white space (\\r, \\n, \\t) is allowed between tokens\n at [Source: java.io.PushbackInputStream@50ebec25; line: 1, column: 2]","path":"/"}
  </code></pre>