gpt4 book ai didi

spring-boot - Spring Boot 应用程序中的重复 Cache-Control header

转载 作者:行者123 更新时间:2023-12-05 06:16:34 25 4
gpt4 key购买 nike

我们有一个在 Openshift 中运行的 Spring Boot 应用程序,我们在其中配置 Cache-Control header ,如下所示:

@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 header :

$ 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

我们期待第一个 header ,但我们不知道第二个 header 来自何处。 (注意第二个 header 名称中的小写 c。)

知道第二个 header 的来源以及我们如何摆脱它吗?

最佳答案

我找到了答案:Cache-control header is added by HAProxy . HAProxy 使用此 header 和 cookie 来创建粘性 session (即确保来自同一客户端的请求由同一 pod 处理)。

参见 this question了解详情。

简而言之,您可以通过以下方式禁用此行为

oc annotate route <myroute> haproxy.router.openshift.io/disable_cookies='true'

关于spring-boot - Spring Boot 应用程序中的重复 Cache-Control header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62064369/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com