为什么不遵守 gzip 最小响应大小?

Daw*_*ura 3 compression spring gzip

我创建了配置以使用 Spring Boot 压缩响应。下面是我的配置。

@Bean
public ServerProperties serverProperties() {
    final ServerProperties serverProperties = new ServerProperties();
    serverProperties.getCompression().setMimeTypes(new String[] {"text/html","text/xml","text/plain","text/css","application/json"});
    serverProperties.getCompression().setEnabled(true);
    return serverProperties;
}
Run Code Online (Sandbox Code Playgroud)

问题是所有响应都有标头 [Content-Encoding ?gzip],即使响应大小小于最小响应大小,默认情况下为 2048 字节。

小智 6

可能与此有关(在我的情况下是):https :
//jira.spring.io/browse/SPR-15212

Spring(mvc) http 响应通常是“传输编码:分块”,因此没有内容长度。
如果没有 content-length,则不能使用 compression.min-response-size。

对于典型的服务器,提供内容长度的技术是here