ehcache

net.sf.ehcache.constructs.web.filter
Class GzipFilter

java.lang.Object
  extended by net.sf.ehcache.constructs.web.filter.Filter
      extended by net.sf.ehcache.constructs.web.filter.GzipFilter
All Implemented Interfaces:
javax.servlet.Filter

public class GzipFilter
extends Filter

Provides GZIP compression of responses.

See the filter-mappings.xml entry for the gzip filter for the URL patterns which will be gzipped. At present this includes .jsp, .js and .css.

Version:
$Id: GzipFilter.java 80 2006-05-14 03:16:22Z gregluck $
Author:
Greg Luck, Adam Murdoch

Field Summary
 
Fields inherited from class net.sf.ehcache.constructs.web.filter.Filter
exceptionsToLogDifferently, exceptionsToLogDifferentlyLevel, filterConfig, NO_FILTER, suppressStackTraces
 
Constructor Summary
GzipFilter()
           
 
Method Summary
protected  boolean acceptsGzipEncoding(javax.servlet.http.HttpServletRequest request)
          Determine whether the user agent accepts GZIP encoding.
protected  void doDestroy()
          A template method that performs any Filter specific destruction tasks.
protected  void doFilter(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.FilterChain chain)
          Performs the filtering for a request.
protected  void doInit()
          Performs initialisation.
 
Methods inherited from class net.sf.ehcache.constructs.web.filter.Filter
acceptsEncoding, destroy, doFilter, filterNotDisabled, getFilterConfig, init, logRequestHeaders
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GzipFilter

public GzipFilter()
Method Detail

doInit

protected void doInit()
               throws java.lang.Exception
Performs initialisation.

Specified by:
doInit in class Filter
Throws:
java.lang.Exception

doDestroy

protected void doDestroy()
A template method that performs any Filter specific destruction tasks. Called from Filter.destroy()

Specified by:
doDestroy in class Filter

doFilter

protected void doFilter(javax.servlet.http.HttpServletRequest request,
                        javax.servlet.http.HttpServletResponse response,
                        javax.servlet.FilterChain chain)
                 throws java.lang.Exception
Performs the filtering for a request.

Specified by:
doFilter in class Filter
Throws:
java.lang.Exception

acceptsGzipEncoding

protected boolean acceptsGzipEncoding(javax.servlet.http.HttpServletRequest request)
Determine whether the user agent accepts GZIP encoding. This feature is part of HTTP1.1. If a browser accepts GZIP encoding it will advertise this by including in its HTTP header:

Accept-Encoding: gzip

Requests which do not accept GZIP encoding fall into the following categories:

As of September 2004, about 34% of Internet requests do not accept GZIP encoding.

Overrides:
acceptsGzipEncoding in class Filter
Parameters:
request -
Returns:
true, if the User Agent request accepts GZIP encoding

ehcache