1

I'm trying to add gzip compression to my server (reading and writing) I've tried it with (spring boot):

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

but when my client sends :

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

with headers :

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

The data reaches the service still compressed. What did I missed?

user_s
  • 1,058
  • 2
  • 12
  • 35

2 Answers2

1

Make sure your client is sending the correct Content-Encoding header, without it Tomcat won't know that decompression is needed. See this answer for details.

Community
  • 1
  • 1
Phil Webb
  • 8,119
  • 1
  • 37
  • 37
1

I ended up using an existing filter :

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

And added a bean for it (new CompressingFilter())

If anyone had the same problem or knows why it didn't work with the spring boot configuration I would love to know.

user_s
  • 1,058
  • 2
  • 12
  • 35