Created
February 6, 2014 17:51
-
-
Save alexandreaquiles/8849163 to your computer and use it in GitHub Desktop.
Filtro que adiciona cabeçalhos HTTP que evitam cache. Baseado em: https://github.com/dropwizard/dropwizard/blob/master/dropwizard-servlets/src/main/java/io/dropwizard/servlets/CacheBustingFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.servlet.*; | |
import javax.servlet.http.HttpServletResponse; | |
import java.io.IOException; | |
public class CacheBustingFilter implements Filter { | |
private static final String CACHE_CONTROL = "Cache-Control"; | |
private static final String CACHE_SETTINGS = "must-revalidate,no-cache,no-store"; | |
@Override | |
public void doFilter(ServletRequest request, | |
ServletResponse response, | |
FilterChain chain) throws IOException, ServletException { | |
if (response instanceof HttpServletResponse) { | |
final HttpServletResponse resp = (HttpServletResponse) response; | |
resp.setHeader(CACHE_CONTROL, CACHE_SETTINGS); | |
} | |
chain.doFilter(request, response); | |
} | |
@Override | |
public void destroy() {} | |
@Override | |
public void init(FilterConfig filterConfig) throws ServletException {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment