title: Disable filter based on response
body: <p>I have a client caching disabling filter which is mapped to all URLs.</p>
  
  <p>Now I have to specifically disable the filter and allow caching when the response has anything other than html.</p>
  
  <p>My current filter code is as follows:</p>
  
  <pre><code>public class NoCacheFilter implements Filter{
  
      @Override
      public void destroy() {}
  
      @Override
      public void doFilter(ServletRequest request, ServletResponse response,
              FilterChain filterChain) throws IOException, ServletException {
          HttpServletResponse httpResponse = (HttpServletResponse) response;
          httpResponse.setHeader("Pragma", "no-cache");
          httpResponse.setHeader("Cache-Control","no-cache,no-store,max-age=0,s-maxage=0,must-revalidate,proxy-revalidate,private,max-stale=0,post-check=0");
          httpResponse.setDateHeader("Expires", 0L);
          filterChain.doFilter(request, response);
      }
  
      @Override
      public void init(FilterConfig arg0) throws ServletException {}
  
  }
  </code></pre>
  
  <p><strong>NOTE</strong>: Just for people who want to know why I am doing this - We have some paged which generate <strong>PDF</strong>. We take this PDF File and flush to the output stream. In IE8, the flush code doesn't work and logs show that <code>the client closed the connetion immaturely...Cannot write to committed response...</code>. When caching is enabled, PDF get written to client normally; without any issue. A separate requirement of the existing app is to not allow caching of any page on the client.</p>