You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by bu...@apache.org on 2008/06/16 14:44:44 UTC

DO NOT REPLY [Bug 43191] compressableMimeType attribute ignored

https://issues.apache.org/bugzilla/show_bug.cgi?id=43191


Richard Mundell <ri...@trgrp.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |richard.mundell@trgrp.com




--- Comment #10 from Richard Mundell <ri...@trgrp.com>  2008-06-16 05:44:43 PST ---
I would like to share an alternative approach for this problem I just
implemented which avoids having to update Tomcat (or patch it).

Grab CompressionFilter.java, CompressionResponseStream.java and
CompressionServletResponseWrapper.java from the Tomcat source code distribution
(I did this with the 5.5.25 source).

Open up CompressionServletResponseWrapper.java and modify the writetoGZip()
method. On line 305, replace...

    response.addHeader("Content-Encoding", "gzip");
    gzipstream = new GZIPOutputStream(output);

...with...

    if ((response.getContentType()!=null) &&
         (response.getContentType().equals("application/pdf")) {

        // I want to compress this content type
        response.addHeader("Content-Encoding", "gzip");
        gzipstream = new GZIPOutputStream(output);
    } else {
        // Don't want to compress this content type
        gzipstream = output;
    }

Compile all three Java classes, then add the filter into your web.xml file:

    <filter>
        <filter-name>Compressing Filter</filter-name>
        <filter-class>compressionFilters.CompressionFilter</filter-class>
        <init-param>
            <param-name>compressionThreshold</param-name>
            <param-value>1</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>Compressing Filter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>


This is very handy if you don't want to upgrade Tomcat, or for Tomcat 5.5.x
users for who there isn't an upgrade with the patch available yet. Also useful
if you don't want to compress server-wide for all of your web applications.

Enjoy!


-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org