Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python zlib not decodable when returned by an http response

I'm using Amazon S3 to serve static files. When the Content-Type is just 'text/css' and I haven't compressed the file, it is returned ok. If I try to zlib.compress() the contents that will be returned and change Content-Encoding to 'gzip', the browser cannot decode the result. In Chrome, the error is

Error 330 net::ERR_CONTENT_DECODING_FAILED

in Safari,

“cannot decode raw data” (NSURLErrorDomain:-1015)

Is there something special to do with python's zlib to make sure the result can be returned and decompressed by the browser?

like image 514
Heinrich Schmetterling Avatar asked Dec 02 '09 20:12

Heinrich Schmetterling


2 Answers

I have this same problem.

If you send the header:

Content-Encoding: gzip

Safari/Chrome show that error.

But if you instead send:

Content-Encoding: deflate

Safari/Chrome decodes the input fine.

like image 183
Jonathan Works Avatar answered Nov 17 '22 07:11

Jonathan Works


gzip is not the same as zlib.

like image 2
Mark Byers Avatar answered Nov 17 '22 08:11

Mark Byers