javaspringspring-bootgzipembedded-tomcat-7

Adding gzip to spring embedded tomcat


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?


Solution

  • 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.