我设置了一个过滤器 bean 来插入和重置Cache-Control
标题。这工作正常,除了在过滤器之后的一点点,Cache-Control
正在插入额外的标题。
我正在与Spring Boot
. 关于可能导致问题的任何解决方案?
@Component
public class CacheControlFilter implements Filter {
@Override
public void init(FilterConfig filterConfig) throws ServletException {}
@Override
public void destroy() {}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
Calendar expires = Calendar.getInstance();
expires.add(Calendar.HOUR, 24);
// Intercept response header
HttpServletResponse resp = (HttpServletResponse) response;
resp.setDateHeader("Expires", expires.getTimeInMillis());
resp.setHeader("Cache-Control", "max-age=2048");
chain.doFilter(request, resp);
}
}
查看重复的Cache-Control
标题:
HTTP/1.1 200 OK
...
Cache-Control: max-age=2048
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Expires: Fri, 26 Sep 2014 18:21:30 GMT
Expires: 0
Pragma: no-cache
Content-Type: image/png
...