views:

33

answers:

1

Hello all I want to make a filter for tomcat to deflate all responces of certain MIME type. Any guidelines?

...
 String ae = request.getHeader("accept-encoding");
        if (ae != null && ae.indexOf("deflate") != -1) {
            deflate response...?????
        }
chain.doFilter(request, res);
+2  A: 

Don't do that in a homebrewed Filter. Configure it at server level. In case of for example Apache Tomcat, just add compression="on" to <Connector> element in /conf/server.xml. It will GZIP responses whenever client accepts it (GZIP is based on deflate and practically every client supports it whenever deflate is supported).

<Connector compression="on">

That's all. You can if necessary configure mime types by compressableMimeType attribute.

See also:

BalusC
Thanks.I have a servlet that responds with json and that responce is not zipped(on a particular request as i noted before the responce was and is the same size) as i saw with firebug.Any ideas?
Argiropoulos Stavros
You're welcome. You already figured that you just have to add `application/json` to `compressableMimeType` attribute, right?
BalusC
Thank you.Sweet...
Argiropoulos Stavros