I'm trying to gzip the output of my controller action to save some bandwidth:
new ByteArrayOutputStream().withStream{ baos ->
new GZIPOutputStream( baos ).withWriter{ it << m.text.bytes }
//def gzip = baos.toByteArray().encodeBase64()
def gzip = new String( baos.toByteArray() )
response.setHeader 'Content-Type', 'application/x-javascript'
response.setHeader 'Content-Encoding', 'x-gzip'
response.outputStream.withStream{ it << gzip }
}
}
when I open the url in a browser it gives me
Unknown Error: net::ERR_CONTENT_DECODING_FAILED
in IE or
Content Encoding Error
in FF
What am I missing?