I'm writing a java servlet on AppEngine. This servlet generates png images. I would like to "gzip" the response. I do it this way:
resp.setHeader("Content-Encoding","gzip");
resp.setContentType("image/png");
// ... png generation ...
GZIPOutputStream gzos = new GZIPOutputStream(resp.getOutputStream());
gzos.write(myPNGdata);
gzos.close();
But: in development server, it's ok, the png displays fine and the response is well gzipped. Then I test on production server (AppEngine) and all I get is a "broken" image...
What could be wrong with my code? Is it related to dev/prod environment?
Off course, If I don't gzip the output, it's ok in both environments.
Thanks for any help.
Edit: I tried this too:
GZIPOutputStream gzos = new GZIPOutputStream(resp.getOutputStream());
gzos.write(ImagesServiceFactory.makeImage(readImage("somePicture.png")).getImageData());
gzos.flush();
gzos.finish();
gzos.close();
and it doesn't work either.
Edit 2: in fact, the response is gzip. I fetched the servlet with "curl theUrl > tmp.gz", then I gunzip "tmp.gz", and the image is fine. But no browser can display it correctly :( What's wrong with my gzip?