Spring Boot gzip 压缩不再起作用

SpringBoot gzip compression not working anymore

从 SpringBoot 2.1.9 升级到 2.2.5 后,gzip 压缩不再起作用。难不成是配置参数变了?

我将 SpringBoot 与 OpenJDK 11 结合使用。

配置参数:

server.compression.enabled=true
# The comma-separated list of mime types that should be compressed
server.compression.mime-types=text/html,text/xml,text/plain,text/css,text/javascript,application/javascript,application/json
# Compress the response only if the response size is at least 1KB
server.compression.min-response-size=1024

我在最新的 chrome 版本中验证了响应 headers。

将 spring 版本从 2.1.11 切换到 2.1.12 时出现问题。嵌入式 tomcat 版本从 9.0.29 更改为 9.0.30.

从 tomcat 9.0.30 开始,压缩将不会用于具有 strong etag 的资产,因此您的资产将以未压缩的方式提供。

我可以通过使 etag weak:

来解决这个问题
val shallowEtagHeaderFilter = ShallowEtagHeaderFilter()
shallowEtagHeaderFilter.isWriteWeakETag = true

参考: