I was adding gzip support to a scalatra app and was a little confused about some of the code in the builtin support. In particular, I don't understand how content length is being set. I was wondering if anyone more familiar with the project or servlets understood what was going on.
On
line 23 an anonymous
HttpServletResponseWrapper is created which has a no-op set content length implementation on it. The code then proceeds to call this no-op setContentLength implementation on
Line 46, using the value obtained from the wrapping
ContentLengthOutputStream class. I've tested and the content length is being set properly on gzip encoded content, so it seems to me that this code is entirely superfluous.
One other thing I noticed is that the GZipOutputstream is being created with the default constructor, which results in a default buffer size of 512 bytes. Which will have a pretty negative impact on performance when gzip larger responses.