将gzip添加到spring嵌入式tomcat中



我正在尝试将gzip压缩添加到我的服务器(读取和写入)我已经尝试过了(spring boot):

server.tomcat.compression=on
server.tomcat.compressableMimeTypes=application/json,application/xml,text/html,text/xml,text/plain

但是当我的客户端发送:

        GZIPOutputStream gzip = new GZIPOutputStream(baos);
        gzip.write(content.getBytes(Charset.forName("UTF8")));
        gzip.close();

with header:

        Accept-Encoding" - "gzip"
        "Content-Encoding" -  "gzip"

数据到达仍处于压缩状态的服务。我错过了什么?

确保您的客户端正在发送正确的Content-Encoding标头,否则Tomcat将不知道需要解压缩。

我最终使用了一个现有的过滤器:

  <dependency>
        <groupId>net.sourceforge.pjl-comp-filter</groupId>
        <artifactId>pjl-comp-filter</artifactId>
        <version>1.7</version>
    </dependency>

并为它添加了一个bean (new CompressingFilter())

如果有人有同样的问题,或者知道为什么它不能与弹簧启动配置工作,我很想知道。

最新更新