title: Updating response after doFilter
body: <p>I wish to add a HTTP header after the <code>doFilter()</code> function has finished running. </p>
  
  <pre><code>public void doFilter(ServletRequest request, ServletResponse response,
                       FilterChain chain) throws IOException, ServletException {
    HttpServletResponse httpResp = (HttpServletResponse) response;
  
    try {
      chain.doFilter(request, httpResp);
  
    } finally {           
      httpResp.setHeader("ADD A HEADER: ", "HEADER");
    }                                     
  }
  </code></pre>
  
  <p>It seems that <code>doFilter</code> flushes the response.</p>
  
  <p><br/></p>
  
  <h1>UPDATE:</h1>
  
  <p>Thanks. After viewing IgorMadjeric and richardtz answers I decided to try Response wrapper:
  <br/><br/><br/>
  This is the wrapper:</p>
  
  <pre><code>public class BufferedHttpServletResponse extends HttpServletResponseWrapper {
  
  public BufferedHttpServletResponse(HttpServletResponse response) {
      super(response);
  }
  
  public void flushBuffer() {
      System.out.println("flush");
  }
  </code></pre>
  
  <p>}</p>
  
  <p>This is the Altered code:</p>
  
  <pre><code>public void doFilter(ServletRequest request, ServletResponse response,
                       FilterChain chain) throws IOException, ServletException {
      HttpServletResponse httpResp = (HttpServletResponse) response;
  
      try {
          BufferedHttpServletResponse bufferedResponse = new BufferedHttpServletResponse(httpResp);
          chain.doFilter(request, bufferedResponse);
  
      } finally {         
          bufferedResponse.setHeader("ADD A HEADER: ", "HEADER");
      }                                       
  }
  </code></pre>
  
  <p>Still does not working. Did I do something wrong?</p>