Wow, sorry but I can't get it to work --- gzip!

472 views
Skip to first unread message

Will Hughes

unread,
Mar 15, 2016, 6:35:46 PM3/15/16
to sparkjava
First off, love sparkJava!  I love anything that works as well as this does and allows me to build things easily and quickly.

But for gzip/http compression, well, the docs on this are very simple:  just turn on the response header and off you go.

I do this and sure enough, see the response header being set to gzip and then .... the browser gives me the dreaded "net::ERR_CONTENT_DECODING_FAILED".

I've set up the system to only compress css files (because nothing was working and it was hard to even see what was going on).

The obvious thing to note is that the Content-Length is the SAME before and after.  Now on systems I've worked on (apache) you usually set a minimum length for compression (as compressing small files is actually slower due to the time to run the compression versus the savings of transferring 100 v. 60 bytes or whatever).

Now, I'm a little confused about the RFC on this point: is the content-length supposed to reflect the compressed size or the uncompressed size WHEN gzip is on?  

Here are the headers I'm seeing in chrome BEFORE turning gzip on:

    1. Request URL:
    2. Request Method:
      GET
    3. Status Code:
      200 OK
    4. Remote Address:
      [::1]:4567
  1. Response Headersview source
    1. Cache-Control:
      max-age=86400
    2. Content-Length:
      9167
    3. Content-Type:
      text/css
    4. Date:
      Tue, 15 Mar 2016 22:29:38 GMT
    5. Expires:
      Wed, 16 Mar 2016 22:29:38 GMT
    6. Server:
      Jetty(9.3.2.v20150730)
    7. Vary:
      Accept-Encoding
  2. Request Headersview source
    1. Accept:
      text/css,*/*;q=0.1
    2. Accept-Encoding:
      gzip, deflate, sdch
    3. Accept-Language:
      en-US,en;q=0.8
    4. Cache-Control:
      no-cache
    5. Connection:
      keep-alive
    6. DNT:
      1
    7. Host:
      localhost:4567
    8. Pragma:
      no-cache
    9. Referer:
    10. User-Agent:
      Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36


And here they are AFTER turning gzip on.

    1. Request URL:
    2. Request Method:
      GET
    3. Status Code:
      200 OK
    4. Remote Address:
      [::1]:4567
  1. Response Headersview source
    1. Cache-Control:
      max-age=86400
    2. Content-Encoding:
      gzip
    3. Content-Length:
      9167
    4. Content-Type:
      text/css
    5. Date:
      Tue, 15 Mar 2016 22:25:59 GMT
    6. Expires:
      Wed, 16 Mar 2016 22:25:59 GMT
    7. Server:
      Jetty(9.3.2.v20150730)
    8. Vary:
      Accept-Encoding
  2. Request Headersview source
    1. Accept:
      text/css,*/*;q=0.1
    2. Accept-Encoding:
      gzip, deflate, sdch
    3. Accept-Language:
      en-US,en;q=0.8
    4. Cache-Control:
      no-cache
    5. Connection:
      keep-alive
    6. DNT:
      1
    7. Host:
      localhost:4567
    8. Pragma:
      no-cache
    9. Referer:
    10. User-Agent:
      Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36


  3. Any ideas or suggestions appreciated.


Will

John Jannotti

unread,
Apr 11, 2016, 8:32:45 AM4/11/16
to sparkjava
I have the same problem. Static files are not compressed despite adding the header. That confuses the browser.

Normal, generated Spark output is compressed properly.

Reply all
Reply to author
Forward
0 new messages