在Spring Boot应用程序中,Cache-Control头重复。

问题描述 投票:2回答:1

我们有一个运行在Openshift中的Spring Boot应用,我们在其中配置了这样的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)。

有什么办法可以解决第二个头的问题吗?

spring-boot openshift cache-control
1个回答
0
投票

我找到了答案。Cache-control头是通过以下方式添加的: HAProxy. HAProxy 使用这个头和一个 cookie 来创建粘性会话(即确保来自同一客户端的请求由同一 pod 处理)。

请看 这个问题 了解详情。

简而言之,你可以通过以下方式来禁止这种行为

oc annotate route <myroute> haproxy.router.openshift.io/disable_cookies='true'
© www.soinside.com 2019 - 2024. All rights reserved.