0

I have an Apache 2.2.15 instance as a proxy in front of a Tomcat application on Red Hat 6.4. I am trying to configure the Apache instance to gzip certain (white-listed content types) responses to the client. Apache is using mod_jk to connect to Tomcat (though the same issue is present when using mod_proxy, so I don't think that my issue is related to mod_jk or Tomcat).

I have this very simple mod_deflate configuration:

AddOutputFilterByType DEFLATE text/html

This causes text/html responses to be gzipped as expected. However, when I try to download files generated by Tomcat, e.g. a spreadsheet with content type application/vnd.ms-excel, those files are also being gzipped:

Here are the response headers when downloading the file directly from Tomcat:

Cache-Control:max-age=0
Content-Disposition:attachment; filename="file-20130322-104702.xls";
Content-Length:699904
Content-Type:application/vnd.ms-excel
Date:Fri, 22 Mar 2013 08:47:02 GMT
Expires:Thu, 01 Jan 1970 00:00:00 GMT
Pragma:public
Server:Apache-Coyote/1.1
Set-Cookie:fileDownloadToken=true; Path=/

And this is when downloading the file via Apache:

Cache-Control:max-age=0
Connection:Keep-Alive
Content-Disposition:attachment; filename="file-20130322-104524.xls";
Content-Encoding:gzip
Content-Type:application/vnd.ms-excel
Date:Fri, 22 Mar 2013 08:45:24 GMT
Expires:Thu, 01 Jan 1970 00:00:00 GMT
Keep-Alive:timeout=30, max=100
Pragma:public
Server:Apache-Coyote/1.1
Set-Cookie:fileDownloadToken=true; Path=/
Transfer-Encoding:chunked
Vary:Accept-Encoding

I can't figure out why mod_deflate is gzipping this response (above)?

After commenting out the line AddOutputFilterByType DEFLATE text/html, the files are no longer gzipped, so I am certain it is that line which is triggering mod_deflate. The same problem is present for file downloads with content-type of application/vnd.openxmlformats-officedocument.spreadsheetml.sheet and possibly others as well. However, downloading a javascript file from Tomcat (via Apache), isn't gzipped (as expected because the content type doesn't match the rule):

Accept-Ranges:bytes
Cache-Control:PUBLIC, max-age=28800, must-revalidate
Connection:Keep-Alive
Content-Length:5578
Content-Type:application/javascript
Date:Fri, 22 Mar 2013 09:09:35 GMT
ETag:W/"5578-1362994418000"
Expires:Fri, 22 Mar 2013 17:09:35 GMT
Keep-Alive:timeout=30, max=100
Last-Modified:Mon, 11 Mar 2013 09:33:38 GMT
Server:Apache-Coyote/1.1

The fact that mod_deflate gzips these spreadsheets is a problem because it causes the response to be buffered, triggering chunked encoding, which I don't want because I want the browser to show a progress monitor (these could be really large files).

Any ideas?

Barry Pitman
  • 3,087
  • 1
  • 24
  • 32

1 Answers1

-1

Use a file extension match to add the header instead:

<filesMatch "\.(html)$">
# Header set Content-Encoding x-deflate
# Header set Content-Encoding deflate
# Header set Content-Encoding gzip
</filesMatch>

Try each one and go with the one which works best.

Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265