views:

258

answers:

2

I recently started using gzip on my site and it worked like a charm on all browsers except Opera which gives an error saying it can not decompress the content due to damaged data. From what I can gather from testing and googling it might be a problem with using both gzip and chunked transfer encoding. The fact that there is no error when requesting small files like css-files also points in that direction.

Is this a known issue or is there something else that I havent thought about?

Someone also mentioned that it could have something to do with sending a Content-Length header.

Here is a simplified version of the most relevant part of my code:

$contents = ob_get_contents();
ob_end_clean();
header('Content-Encoding: '.$encoding);
print("\x1f\x8b\x08\x00\x00\x00\x00\x00");
$size = strlen($contents);
$contents = gzcompress($contents, 9);
$contents = substr($contents, 0, $size);
print($contents);
exit();
+1  A: 

GZip and chunked encoding are used together all of the time on the Web, so I doubt the problem is caused by that alone.

You shouldn't send a Content-Length header if chunked encoding is in use.

Also, when you negotiate for gzip, you should send Vary: Accept-Encoding (on compressed and uncompressed responses), and if you send ETags, they need to be different for the compressed and uncompressed responses.

Try running the URL through http://redbot.org/ -- it checks for a few common problems with gzip encoding.

Mark Nottingham
A: 

Ideally, you should check the request header from the client to make sure it supports an encoded response. The header to look for is : "Accept-Encoding: gzip,deflate". You should also probably check whether the client is using HTTP 1.1.

thushara