我設置了一個過濾器bean來插入緩存控制標頭。這工作正常,除了在過濾器之後的某個時刻,插入了額外的緩存控制標頭。Spring Boot - Duplicate Headers
我正在使用Spring Boot。
關於可能導致此問題的任何想法?
public class CacheControlFilter extends GenericFilterBean {
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
Calendar expires = Calendar.getInstance();
expires.add(Calendar.HOUR, 24);
HttpServletResponse httpResponse = (HttpServletResponse) response;
// Returns false
System.out.println("==========> " + httpResponse.containsHeader("Cache-Control"));
httpResponse.addHeader("Cache-Control", "max-age=" + (expires.getTimeInMillis()/1000));
httpResponse.addDateHeader("Expires", expires.getTimeInMillis());
chain.doFilter(request, response);
}
}
看到重複的高速緩存控制標題:
HTTP/1.1 200 OK
...
Cache-Control: max-age=1411755690
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
...
不是禁用所有Spring Security的頭,你可能希望縮小範圍,這樣你仍然可以得到其他的頭,而插入你自己的緩存控制。有關更多詳細信息,請閱讀http://docs.spring.io/spring-security/site/docs/3.2.5/reference/htmlsingle/#default-security-headers。 – gregturn 2014-09-26 19:36:13
到春季文檔的鏈接不再有效。我想這一個現在是好的:http://docs.spring.io/spring-security/site/docs/current/reference/htmlsingle/#default-security-headers – 2016-03-17 09:14:21
這個解決方案禁用Spring Security的所有頭文件。 – 2017-12-20 13:35:31