Search code examples
nettymicronaut

How do I disable gzip compression in micronaut 3.9.x?


Newer micronaut versions have settings to disable compression in responses by setting the compression-threshold = -1 or compression-level to 0. Older versions don't support this in the DefaultHttpCompressionStrategy.


Solution

  • The workaround is to create a CustomHttpCompressionStrategy as follows:

    @Primary
    @Singleton
    public class CustomHttpCompressionStrategy implements HttpCompressionStrategy {
      public boolean shouldCompress(io.netty.handler.codec.http.HttpResponse response) {
        return false;
      }
    
      public int getCompressionLevel() {
        return 0;
      }
    }