In tomcat/conf/server.xml, I enabled gzip compression as below.
compression="on" compressableMimeType="application/json" compressionMinSize="2048"
I’d like to check any solution when client explicitly pass “Accept-Encoding: gzip,deflate” in Request Header, then tomcat retunr response payload with gzip compressed.
Otherwise, When no more key-value in request header, tomcat by default return the payload without gzip compression.
Is it possible?
What you describe is the default behavior of Tomcat. Unless it finds the Accept-Encoding header containing the value gzip, it will not compress the output.
If you want to implement your own, very specific compression, then you can start with the Tomcat sources
CompressionFilterandCompressionServletResponseWrapper.