public class AsyncGzipFilter extends UserAgentFilter implements GzipFactory
minGzipSize
initParameter or the minGzipSize is 0(default)mimeTypes
init parameter, then the Content-Type is in the list.excludedMimeTypes
Compressing the content can greatly improve the network bandwidth usage, but at a cost of memory and
CPU cycles. If this filter is mapped for static content, then use of efficient direct NIO may be
prevented, thus use of the gzip mechanism of the DefaultServlet
is
advised instead.
This filter extends UserAgentFilter
and if the the initParameter excludedAgents
is set to a comma separated list of user agents, then these agents will be excluded from gzip content.
Init Parameters:
IllegalArgumentException
.
See: GZIPOutputStream.GZIPOutputStream(java.io.OutputStream, int)
and: DeflaterOutputStream.DeflaterOutputStream(java.io.OutputStream, Deflater, int)
minGzipSize
.
Deflater.Deflater(int, boolean)
Deflater.Deflater(int, boolean)
String.contains(CharSequence)
to check if the excluded agent occurs
in the user-agent header. If it does -> no compression
String.startsWith(String)
comparison to check if the path matches.
If it does match -> no compression. To match subpaths use excludePathPatterns
instead.
Modifier and Type | Field and Description |
---|---|
protected static ThreadLocal<byte[]> |
_buffer |
protected int |
_bufferSize |
protected boolean |
_checkGzExists |
protected ServletContext |
_context |
protected int |
_deflateCompressionLevel |
protected boolean |
_deflateNoWrap |
protected ThreadLocal<Deflater> |
_deflater |
protected Set<Pattern> |
_excludedAgentPatterns |
protected Set<String> |
_excludedAgents |
protected Set<Pattern> |
_excludedPathPatterns |
protected Set<String> |
_excludedPaths |
protected boolean |
_excludeMimeTypes |
protected Set<String> |
_methods |
protected Set<String> |
_mimeTypes |
protected int |
_minGzipSize |
protected HttpField |
_vary |
static int |
DEFAULT_MIN_GZIP_SIZE |
static String |
DEFLATE |
static String |
ETAG |
static String |
GZIP |
Constructor and Description |
---|
AsyncGzipFilter() |
Modifier and Type | Method and Description |
---|---|
void |
destroy() |
void |
doFilter(ServletRequest req,
ServletResponse res,
FilterChain chain) |
int |
getBufferSize() |
Deflater |
getDeflater(Request request,
long content_length) |
HttpField |
getVaryField() |
void |
init(FilterConfig filterConfig) |
boolean |
isExcludedMimeType(String mimetype) |
void |
recycle(Deflater deflater) |
getUserAgent, getUserAgent
public static final String GZIP
public static final String DEFLATE
public static final String ETAG
public static final int DEFAULT_MIN_GZIP_SIZE
protected ServletContext _context
protected boolean _excludeMimeTypes
protected int _bufferSize
protected int _minGzipSize
protected int _deflateCompressionLevel
protected boolean _deflateNoWrap
protected boolean _checkGzExists
protected final ThreadLocal<Deflater> _deflater
protected static final ThreadLocal<byte[]> _buffer
protected HttpField _vary
public void init(FilterConfig filterConfig) throws ServletException
init
in interface Filter
init
in class UserAgentFilter
ServletException
UserAgentFilter.init(javax.servlet.FilterConfig)
public void destroy()
destroy
in interface Filter
destroy
in class UserAgentFilter
UserAgentFilter.destroy()
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException
doFilter
in interface Filter
doFilter
in class UserAgentFilter
IOException
ServletException
UserAgentFilter.doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)
public HttpField getVaryField()
getVaryField
in interface GzipFactory
public Deflater getDeflater(Request request, long content_length)
getDeflater
in interface GzipFactory
public void recycle(Deflater deflater)
recycle
in interface GzipFactory
public boolean isExcludedMimeType(String mimetype)
isExcludedMimeType
in interface GzipFactory
public int getBufferSize()
getBufferSize
in interface GzipFactory
Copyright © 1995-2014 Mort Bay Consulting. All Rights Reserved.