tomcat 安全约束影响缓存

标签 tomcat cache-control security-constraint

我在缓存我的应用程序时遇到问题。

将这段代码添加到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/

相关文章:

java - 在 Tomcat 中使用 Jersey 作为 Servlet 的 Spring Boot

apache - 如何在 Apache Tomcat 8.0.9 中重定向带有端口号的 URL,以便用户看不到端口号

nginx - 缓存控制 header 重复;有效与否? (Nginx)

caching - NGINX `expires -1` 指令中的 `location` 是什么意思?

css - 连接 CSS 与缓存控制

security - Tomcat 7 - 多个安全约束不起作用

java - 无法发布到服务器。无法获取 J2EEFlexProjDeployable 对象

java - tomcat 8 嵌入式模式下的 JasperInitializer

java - 过滤涉及安全约束的请求

tomcat - 302 服务器重定向 - 'Location' header URL 从 HTTP 更改为 HTTPS