开发者

Post-Gzip contentLength in Tomcat Custom Valve

开发者 https://www.devze.com 2022-12-25 07:39 出处:网络
In a cu开发者_JAVA百科stom Tomcat Valve is there any way to get the contentLength after the content has been gzipped?response.getContentCountLong() returns the pre-gzipped size.With GZIP, the total le

In a cu开发者_JAVA百科stom Tomcat Valve is there any way to get the contentLength after the content has been gzipped? response.getContentCountLong() returns the pre-gzipped size.


With GZIP, the total length of the compressed content is unpredictable beforehand. It's only known when the last bit has been compressed. In Tomcat, a GZIP response is usually directly sent in chunks (with Transfer-Encoding: chunked) and never fully buffered in memory beforehand since this may be memory hogging. So I don't see ways to get the content length beforehand other than counting the bytes written to the outputstream yourself, or manually buffering the entire outputstream of the response and manually sending/flushing it fully on close (which may be memory hogging).

0

精彩评论

暂无评论...
验证码 换一张
取 消