Spring Security-无法避免缓存控制 [英] Spring Security - No way to avoid cache-control
问题描述
我有一个应用程序,并使用spring的控制器映射将图像加载到我的用户. (InputStream,响应等).
I have an application and use a controller mapping of spring to load images to my users. (InputStream, response, etc).
在我的控制器中,我将标头设置为缓存控制,基于文件等.但是始终存在杂乱:所有请求中都包含no-cache和Cache-Control:"max-age = 0",并且替换了我的响应设置
In my controller I set headers to cache-control, baseaded on files, etc. But there's always pragma: no-cache and Cache-Control:"max-age=0" inside all requests, and that's replace my response settings.
我正尽一切努力来解决这个问题,但没有任何效果.
I was trying everything to solve this, but nothing works.
我已经阅读了所有页面,并尝试了有关此问题的所有发现: http://docs .spring.io/autorepo/docs/spring-security/3.2.0.CI-SNAPSHOT/reference/html/headers.html
I already read all page and try everything I found about that: http://docs.spring.io/autorepo/docs/spring-security/3.2.0.CI-SNAPSHOT/reference/html/headers.html
我的spring security.xml具有:
My spring security.xml has:
<security:headers disabled="true"/>
有人有解决这个问题的好主意吗?
Anyone have a good idea to solve this?
请记住,要加载需要通过控制器加载的图像,我永远不会直接调用static.
Remember that to load the images I need to load through my controller, I never call static directly.
推荐答案
Cache-Control
标头可以通过在HttpServletResponse
中覆盖它们而在每个动作的基础上进行控制:
The Cache-Control
headers can be controlled on a per action basis by overriding them in the HttpServletResponse
:
@RequestMapping(value = "/foo", method = RequestMethod.GET)
public String someAction(HttpServletResponse response) {
response.setHeader("Cache-Control", "no-transform, public, max-age=86400");
// ...
}
无需摆弄Spring Security配置.
No need to fiddle with the Spring Security configuration.
这篇关于Spring Security-无法避免缓存控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!