title: GZip encoding in Jersey
body: <p>I'm writing a RESTful web service in Jersey 2. I want to support the Gzip encoding for the responses. Following <a href="https://stackoverflow.com/a/22763571">this answer</a>, I enabled the <code>org.glassfish.jersey.server.filter.EncodingFilter</code> in my <code>ResourceConfig</code> class.</p>
  
  <pre><code>public class MyWebService extends ResourceConfig {
      public MyWebService() {
          register(EncodingFilter.class);
          register(GZipEncoder.class);
          register(DeflateEncoder.class);
      }
  }
  </code></pre>
  
  <p>On my resource class, I'm returning a <code>javax.ws.rs.core.Response</code> object.</p>
  
  <pre><code>@GET
  @Path("api/configs") 
  public Response listConfigs() throws Exception {
      List&lt;UserConfig&gt; configs = configService.getAll();
      return Response.ok().entity(configs).build();
  }
  </code></pre>
  
  <p>Now when I hit this api, I get a response but the response headers do not contain a <code>Content-Encoding</code> header, rather it contains <code>Transfer-Encoding: chunked</code>.</p>
  
  <p>Request:</p>
  
  <pre><code>&gt; GET /api/configs HTTP/1.1
  &gt; Accept-Encoding: gzip
  </code></pre>
  
  <p>Response:</p>
  
  <pre><code>&gt; HTTP/1.1 200 
  &gt; Transfer-Encoding: chunked
  * Received 14.8 KB chunk
  * Received 504 B chunk
  * Received 15.2 KB chunk
  * Received 506 B chunk
  * Received 15.1 KB chunk
  * Received 514 B chunk
  </code></pre>
  
  <p>There is no <code>Content-Encoding: gzip</code> header in the response, nor there is any <code>Content-Length</code> header.</p>
  
  <p>I'm using <code>Jersey 2.27</code> on <code>Tomcat 9</code>.</p>
  
  <p>Is there any other configuration I'm missing? How do I get these two headers and get the response as gzip compressed rather than receiving chunked response?</p>
  
  <p><strong>Edit</strong>: I have noticed that when I send large files ( > 1000 KB) I get both the <code>Content-Encoding: gzip</code> and <code>Transfer-Encoding: chunked</code> headers.</p>