我在缓存我的应用程序时遇到问题。
将这段代码添加到tomcat的web.xml中时:
<security-constraint>
<web-resource-collection>
<web-resource-name>HTTPSOnly</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
我收到了这样的回复:
Cache-Control private
Date Tue, 18 Feb 2014 01:18:17 GMT
Etag W/"200-1391558564593"
Expires Thu, 01 Jan 1970 00:00:00 WET
Server Apache-Coyote/1.1
没有这段代码一切都很好:
Accept-Ranges bytes
Cache-Control max-age=604800
Content-Length 1496
Content-Type text/css
Date Tue, 18 Feb 2014 01:21:26 GMT
Etag W/"1496-1391558561359"
Expires Tue, 25 Feb 2014 01:21:27 GMT
Last-Modified Wed, 05 Feb 2014 00:02:41 GMT
Server Apache-Coyote/1.1
谁能说出是什么原因导致的问题?以及为什么此代码将缓存控制更改为我的应用程序的私有(private)。非常感谢
Tomcat 7.0
JDK : 1.6
最佳答案
根据 Oracle Java EE 6 tutorial , 指定 user-data-constraint
将使用“CONFIDENTIAL”
when the application requires that data be transmitted so as to prevent other entities from observing the contents of the transmission.
对于 HTTP 响应,这意味着确保从服务器返回客户端的过程中没有代理/缓存能够缓存该响应并提供给任何其他请求客户端。因此使用:
Cache-Control: private
虽然您可能想使用“INTEGRAL”而不是“CONFIDENTIAL”,但同一教程指出许多 Java EE 服务器对这两个值的处理方式相同。
如果您的应用程序需要允许缓存,我怀疑您需要删除 <user-data-constraint>
来自您的 web.xml
的元素文件。
希望这对您有所帮助!
关于tomcat 安全约束影响缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21829553/