title: Accessing Request Headers
body: <p>How to access request headers in implementation of WriterInterceptor interface in JAX-RS?</p>
  
  <pre><code>context.getHeaders(); //This line gives a set of response headers(not request headers) in the WriterInterceptor implementation.
  </code></pre>
  
  <p>Complete code below:</p>
  
  <pre><code>public class GzipFilterWriterInterceptor implements WriterInterceptor {
  
  private static final Logger LOG = LoggerFactory.getLogger(GzipFilterWriterInterceptor.class);
  
  @Override
  public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException {
      MultivaluedMap&lt;String,Object&gt; headers = context.getHeaders();
      headers.add("Content-Encoding", "gzip");
  
  
      final OutputStream outputStream = context.getOutputStream();
      context.setOutputStream(new GZIPOutputStream(outputStream));
      context.proceed();
  }
  
  }
  </code></pre>