public class GzipFilter extends UserAgentFilter
minGzipSize
initParameter or the minGzipSize is 0(default)mimeTypes
init parameter, then the Content-Type is in the list.excludedMimeTypes
If both gzip and deflate are specified in the accept-encoding header, then gzip will be used.
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 String |
_vary |
static String |
DEFLATE |
static String |
ETAG |
static String |
ETAG_DEFLATE |
static String |
ETAG_GZIP |
static String |
GZIP |
Constructor and Description |
---|
GzipFilter() |
Modifier and Type | Method and Description |
---|---|
protected void |
configureWrappedResponse(CompressedResponseWrapper wrappedResponse) |
protected CompressedResponseWrapper |
createWrappedResponse(HttpServletRequest request,
HttpServletResponse response,
String compressionType) |
void |
destroy() |
void |
doFilter(ServletRequest req,
ServletResponse res,
FilterChain chain) |
void |
init(FilterConfig filterConfig) |
getUserAgent, getUserAgent
public static final String GZIP
public static final String ETAG_GZIP
public static final String DEFLATE
public static final String ETAG_DEFLATE
public static final String ETAG
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 String _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)
protected CompressedResponseWrapper createWrappedResponse(HttpServletRequest request, HttpServletResponse response, String compressionType)
protected void configureWrappedResponse(CompressedResponseWrapper wrappedResponse)
Copyright © 1995-2015 Webtide. All Rights Reserved.