org.eclipse.jetty.servlets
Class GzipFilter
java.lang.Object
org.eclipse.jetty.servlets.UserAgentFilter
org.eclipse.jetty.servlets.GzipFilter
- All Implemented Interfaces:
- javax.servlet.Filter
- Direct Known Subclasses:
- IncludableGzipFilter
public class GzipFilter
- extends UserAgentFilter
GZIP Filter
This filter will gzip the content of a response iff:
- The filter is mapped to a matching path
- The response status code is >=200 and <300
- The content length is unknown or more than the
minGzipSize
initParameter or the minGzipSize is 0(default)
- The content-type is in the comma separated list of mimeTypes set in the
mimeTypes
initParameter or
if no mimeTypes are defined the content-type is not "application/gzip"
- No content-encoding is specified by the resource
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.
Method Summary |
void |
destroy()
|
void |
doFilter(javax.servlet.ServletRequest req,
javax.servlet.ServletResponse res,
javax.servlet.FilterChain chain)
|
void |
init(javax.servlet.FilterConfig filterConfig)
|
protected GzipResponseWrapper |
newGzipResponseWrapper(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Allows derived implementations to replace ResponseWrapper implementation. |
protected PrintWriter |
newWriter(OutputStream out,
String encoding)
Allows derived implementations to replace PrintWriter implementation. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
_mimeTypes
protected Set<String> _mimeTypes
_bufferSize
protected int _bufferSize
_minGzipSize
protected int _minGzipSize
_excluded
protected Set<String> _excluded
GzipFilter
public GzipFilter()
init
public void init(javax.servlet.FilterConfig filterConfig)
throws javax.servlet.ServletException
- Specified by:
init
in interface javax.servlet.Filter
- Overrides:
init
in class UserAgentFilter
- Throws:
javax.servlet.ServletException
- See Also:
UserAgentFilter.init(javax.servlet.FilterConfig)
destroy
public void destroy()
- Specified by:
destroy
in interface javax.servlet.Filter
- Overrides:
destroy
in class UserAgentFilter
- See Also:
UserAgentFilter.destroy()
doFilter
public void doFilter(javax.servlet.ServletRequest req,
javax.servlet.ServletResponse res,
javax.servlet.FilterChain chain)
throws IOException,
javax.servlet.ServletException
- Specified by:
doFilter
in interface javax.servlet.Filter
- Overrides:
doFilter
in class UserAgentFilter
- Throws:
IOException
javax.servlet.ServletException
- See Also:
UserAgentFilter.doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)
newGzipResponseWrapper
protected GzipResponseWrapper newGzipResponseWrapper(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
- Allows derived implementations to replace ResponseWrapper implementation.
- Parameters:
request
- the requestresponse
- the response
- Returns:
- the gzip response wrapper
newWriter
protected PrintWriter newWriter(OutputStream out,
String encoding)
throws UnsupportedEncodingException
- Allows derived implementations to replace PrintWriter implementation.
- Parameters:
out
- the outencoding
- the encoding
- Returns:
- the prints the writer
- Throws:
UnsupportedEncodingException
Copyright © 1995-2012 Mort Bay Consulting. All Rights Reserved.