Thanks, the latest versions of Tomcat 4.1 already support it.

--------
David

-----Mensaje original-----
De: Nicolas Toper [mailto:[EMAIL PROTECTED]
Enviado el: lunes, 15 de diciembre de 2003 18:56
Para: [EMAIL PROTECTED]
Asunto: Re: gzip compression

Apache could do that automatically...

Otherwise, I'd use Tomcat and a filter servlet to do it: you could find some
all ready to be used on the Web...
Le Lundi 15 Décembre 2003 18:46, Carmona Perez, David a écrit :
> Hi all,
>
> Does someone how can I make some action that activates compressing output
> data using GZip?  Gzip compression is an HTTP 1.1 standard feature.
>
> Ideally it would be great if it could be like an action, so that it's easy
> to activate it on or off. I have tried this code:
>
> import java.io.IOException;
> import java.io.OutputStream;
> import java.util.Map;
> import java.util.zip.GZIPOutputStream;
>
> import javax.servlet.ServletOutputStream;
> import javax.servlet.http.HttpServletResponse;
>
> import org.apache.avalon.framework.parameters.Parameters;
> import org.apache.cocoon.acting.AbstractAction;
> import org.apache.cocoon.environment.ObjectModelHelper;
> import org.apache.cocoon.environment.Redirector;
> import org.apache.cocoon.environment.Request;
> import org.apache.cocoon.environment.SourceResolver;
> import org.apache.cocoon.environment.http.HttpEnvironment;
> import org.apache.cocoon.environment.http.HttpResponse;
>
> public class CompressAction extends AbstractAction {
>       class StreamGzip extends ServletOutputStream {
>               public StreamGzip(OutputStream out) throws IOException {
>                       gzip = new GZIPOutputStream(out);
>               }
>               /** @see java.io.OutputStream#write(int) */
>               public void write(int b) throws IOException {
>                       gzip.write(b);
>               }
>               /** @see java.io.OutputStream#close() */
>               public void close() throws IOException {
>                       gzip.close();
>               }
>               /** @see java.io.OutputStream#flush() */
>               public void flush() throws IOException {
>                       gzip.flush();
>               }
>               private GZIPOutputStream gzip;
>       }
>       class GzipResponse extends HttpResponse {
>               GzipResponse(HttpServletResponse resp) throws IOException {
>                       super(resp);
>                       os = new StreamGzip(resp.getOutputStream());
>               }
>               public ServletOutputStream getOutputStream() throws IOException {
>                       return os;
>               }
>               StreamGzip os;
>       }
>       public Map act(Redirector redirector, SourceResolver resolver, Map
> objectModel, String source, Parameters parameters) throws Exception {
> Request pet = ObjectModelHelper.getRequest(objectModel);
>               String accept = pet.getHeader("Accept-Encoding");
>               if (accept != null && accept.indexOf("gzip") >= 0) {
>                       GzipResponse resp = new
> GzipResponse((HttpServletResponse)objectModel.get(HttpEnvironment.HTTP_RESP
>ONSE_OBJECT)); resp.setHeader("Content-Encoding", "gzip");
>                       objectModel.put(ObjectModelHelper.RESPONSE_OBJECT, resp);
>                       return EMPTY_MAP;
>               }
>               return null;
>       }
> }
>
> But it doesn't work, because the HttpEnvironment holds also holds a
> reference to the outputstream. Which is the cleanest way to perform this?
> Any suggestion will be greatly appreciated.
>
>
> --------
> David
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to