spring-boottomcatgziphttp-compressioncontent-encoding

spring boot response encoding not working


I've configured my spring boot(2.5.5) application to enable response encoding by providing below properties in application.properties I'm using the default embedded tomcat as a container

server.tomcat.compression=on
server.tomcat.compression.min-response-size=1
server.tomcat.compression.mime-types=application/json

my request headers contain Accept-Encoding: gzip Still response is not being encoded.

I had digged a bit deep into the request flow by setting up breakpoints and found that there is a class org.apache.coyote.http11.AbstractHttp11Protocol having a method

 public boolean useCompression(Request request, Response response) {
        return compressionConfig.useCompression(request, response);
    }

What i find here is that the compression properties set by me in the config file is not propogated to the object compressionConfig. This still has the default values with no compression and minSize as 2048 if i try to tweak the compressionConfig object during the debug session and set the required values this works. But how do i actually get it to work ? Any help will be appreciated


Solution

  • For spring boot 2.5.5 you should use properties like this:

    server.compression.enabled=true
    server.compression.min-response-size=300KB