tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 43191] compressableMimeType attribute ignored
Date Mon, 16 Jun 2008 12:44:44 GMT
https://issues.apache.org/bugzilla/show_bug.cgi?id=43191


Richard Mundell <richard.mundell@trgrp.com> changed:

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




--- Comment #10 from Richard Mundell <richard.mundell@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


Mime
View raw message