Spring boot version is 2.3.4.RELEASE
Good day , for some particular reasons I can't enable Gzip compression in reverse proxy server so I want to do it in Spring's Tomcat side. The only way to customize compression that I found is using the following properties
server.compression.min-response-size=
server.compression.enabled=
However, as far as I can see for Tomcat CompressionConnectorCustomizer class is used which calls
Compression compression = this.compression;
protocol.setCompression("on");
and inside of CompressionConfig.setCompression method it checks if String is equals to on if so then compression level is 1.
For my use case I need to change this compression level. Gzip allows 9 compression levels and I want to use level 6. Is there any way I can configure it through application.properties ? If no then are you planning to integrate it ? If so then maybe I can try to contribute by adding additional configuration property . Regards !
Comment From: wilkinsona
AFAIK, CompressionConfig’s levels are not Gzip compression levels. It uses 0 to disable compression, 1 to enable it subject to the response meeting the minimum size requirement, and 2 to force compression irrespective of the response size. Any other integer value enables compression (level 1) and sets the mimimum size for a response to be compressed.
For the actual compression, Tomcat uses the JDK’s GZIPOutputStream with its default level of compression. It doesn’t offer a way to configure the level (and the JDK does not make it particularly easy to do so anyway).
Given that Tomcat does not offer a way to configure the level of gzip compression that it uses, I’ll close this one. Thanks anyway for the suggestion.
Comment From: strogiyotec
@wilkinsona thanks for detailed explanation. I didn't know that compression level paramater in Tomcat works as a enum rather than a gzip level.