GZip Support

49 views
Skip to first unread message

jschl...@localytics.com

unread,
Apr 5, 2017, 3:43:01 PM4/5/17
to scalatra-user
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.

Naoki Takezoe

unread,
May 7, 2017, 3:36:14 AM5/7/17
to scalatra-user
Thanks, I raised an issue in GitHub:
https://github.com/scalatra/scalatra/issues/659

2017年4月6日木曜日 4時43分01秒 UTC+9 jschl...@localytics.com:

Ivan Porto Carrero

unread,
May 7, 2017, 3:40:49 AM5/7/17
to scalatra-user
Jetty has a better gzip filter that you can use instead.

The reason that there is a noop for the response wrapper is because we need to count the bytes after compressing

A bigger issue is the buffer size that's correct. 

Also it will still try to compress when transfer encoding is set to chunked, it shouldn't actually be setting the content length then.
I think it would be better if this is removed from scalatra and document

Naoki Takezoe

unread,
May 7, 2017, 4:05:57 AM5/7/17
to scalat...@googlegroups.com
> The reason that there is a noop for the response wrapper is because we need to count the bytes after compressing

Do you mean response.setContentLength(s.length) in this line?
https://github.com/scalatra/scalatra/blob/master/core/src/main/scala/org/scalatra/GZipSupport.scala#L46

But it looks to be ignored, so I don't know where properly length is set...

> I think it would be better if this is removed from scalatra and document

Anyway, agree. I updated the issue.

--
Naoki Takezoe

Ivan Porto Carrero

unread,
May 7, 2017, 10:56:12 AM5/7/17
to scalatra-user

Naoki Takezoe

unread,
May 7, 2017, 6:39:46 PM5/7/17
to scalat...@googlegroups.com
Counted there, but where is the counted value set to response if
response.setContentLength(s.length) is ignored?
> --
> You received this message because you are subscribed to the Google Groups
> "scalatra-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to scalatra-use...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Naoki Takezoe
Reply all
Reply to author
Forward
0 new messages