Deflate and IE

Created: 2013/03/29 21:00:36+0000 Revised: 2013/03/29 21:41:53+0000 Revisions:  2 1

When I recently added support for the deflate content encoding I broke my website in IE. The static content became unreadable in IE. It turns out that IE only accepts raw deflate data without a wrapper.

This means that within the code for compression I need to match on the User-Agent header. Any IE browser requesting deflate receives the raw deflate encoding and any other browser requesting deflate receives the wrapped deflate encoding.

The deflate wrapper is defined in RFC 1950 and the deflate compression format is defined in RFC 1951. The wrapper has a two byte header which identifies the compression method and any flags.

To exclude the wrapper using the Java package you need to create a Deflater object. The Deflater object allows properties of the deflation algorithm to be set.

Deflater deflater = new Deflater(Deflater.BEST_COMPRESSION,true); DeflaterOutputStream compressedStream = new DeflaterOutputStream(outputStream,deflater);

The Deflater constructor takes a multiple arguments. The example above shows the highest level or compression being used and the wrapper being excluded. The second argument is a boolean value that removes the wrapper when true.

Thanks to Billy Hoffman for helping me to understand the problem. He does suggest that you just use gzip but it took me longer to understand the problem than to fix it.