Sim*_*ion 2 spring spring-boot spring-cache
我设置了一个过滤器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);
}
}
Run Code Online (Sandbox Code Playgroud)
查看重复的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
...
Run Code Online (Sandbox Code Playgroud)
你在使用Spring-security吗?
Spring安全性也会自动添加它们,您可以在配置中禁用它们,如下所示:
class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override protected void configure(HttpSecurity http) throws Exception {
//... Rest of config
http.headers().disable()
Run Code Online (Sandbox Code Playgroud)
详情请见:http: //docs.spring.io/autorepo/docs/spring-security/3.2.2.RELEASE/apidocs/org/springframework/security/config/annotation/web/configurers/HeadersConfigurer.html
您还可以根据需要配置要打开/关闭的特定标头(请参阅该API文档中的其他方法,例如cacheControl()等)
| 归档时间: |
|
| 查看次数: |
1662 次 |
| 最近记录: |