I'm trying to send the output of my servlet compressed to the browser,
depending on the 'Accept-Encoding' header in the HTTP request.

I've followed the HTTP1.1 spec, but it seems that I'm doing something wrong.
This is the code I'm using:

//-----------------------------
// htmlOut is a StringBuffer that has the data to send to the browser.
if      (req.getHeader("Accept-Encoding").indexOf("gzip") >= 0)
{
        res.setHeader("Content-Encoding", "gzip");
        res.setHeader("Transfer-Encoding","chunked");

        res.getOutputStream().write(new
String(Long.toHexString(htmlOut.length()).toUpperCase() +
"\r\n").getBytes());

        GZIPOutputStream gzOut = new GZIPOutputStream(res.getOutputStream());
        gzOut.write(htmlOut.toString().getBytes());
        gzOut.close();

        res.getOutputStream().write(new String("\r\n0\r\n\r\n").getBytes());
        res.getOutputStream().close();
}
//---------------------

If someone was able to do it, send me a clue.

Regards.

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to