Spring Boot 应用程序中的重复 Cache-Control 标头

3
我们有一个Spring Boot应用程序在Openshift上运行,我们可以这样配置Cache-Control头:
@Configuration
@EnableWebSecurity
public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.headers().cacheControl().disable().addHeaderWriter((httpServletRequest, httpServletResponse) -> {
            httpServletResponse.setHeader(HttpHeaders.CACHE_CONTROL, "public, max-age=86400");
        });
    }
}

在HTTP响应中有两个Cache-Control头:
$ curl --header https://<our-url> --head
HTTP/1.1 200 Connection established

HTTP/1.1 200
...
Cache-Control: public, max-age=86400
...
Cache-control: private

我们期望出现第一个标题,但我们不知道第二个标题从哪里来的。(请注意第二个标题名称中的小写字母c。)
有任何想法是第二个标题来自何处以及如何去掉它吗?
1个回答

1
我找到了答案:缓存控制头由HAProxy添加。 HAProxy使用此标头和cookie创建粘性会话(即确保来自同一客户端的请求由同一Pod处理)。
有关详细信息,请参见此问题
简而言之,您可以通过以下方式禁用此行为:
oc annotate route <myroute> haproxy.router.openshift.io/disable_cookies='true'

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接