public class GzipHandler extends HandlerWrapper implements GzipFactory
HttpOutput.Interceptor
mechanism.
The handler can be applied to the entire server (a gzip.mod is included in the distribution) or it may be applied to individual contexts.
AbstractLifeCycle.AbstractLifeCycleListener
LifeCycle.Listener
Container.InheritedListener, Container.Listener
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_MIN_GZIP_SIZE |
static String |
DEFLATE |
static String |
ETAG |
static String |
ETAG_GZIP |
static String |
GZIP |
_handler
Constructor and Description |
---|
GzipHandler()
Instantiates a new gzip handler.
|
Modifier and Type | Method and Description |
---|---|
void |
addExcludedAgentPatterns(String... patterns) |
void |
addExcludedMimeTypes(String... types)
Set the mime types.
|
void |
addExcludedPaths(String... pathspecs) |
void |
addIncludedMethods(String... methods) |
void |
addIncludedMimeTypes(String... types)
Add included mime types.
|
void |
addIncludedPaths(String... pathspecs)
Add path specs to include.
|
protected void |
doStart()
Starts the managed lifecycle beans in the order they were added.
|
boolean |
getCheckGzExists() |
int |
getCompressionLevel() |
Deflater |
getDeflater(Request request,
long content_length) |
String[] |
getExcludedAgentPatterns() |
String[] |
getExcludedMimeTypes() |
String[] |
getExcludedPaths() |
String[] |
getIncludedMimeTypes() |
String[] |
getIncludedPaths() |
String[] |
getMethods() |
int |
getMinGzipSize()
Get the minimum reponse size.
|
void |
handle(String target,
Request baseRequest,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Handle a request.
|
protected boolean |
isExcludedAgent(String ua)
Checks to see if the userAgent is excluded
|
boolean |
isMimeTypeGzipable(String mimetype) |
protected boolean |
isPathGzipable(String requestURI)
Checks to see if the path is included or not excluded
|
void |
recycle(Deflater deflater) |
void |
setCheckGzExists(boolean checkGzExists) |
void |
setCompressionLevel(int compressionLevel) |
void |
setExcludedAgentPatterns(String... patterns) |
void |
setExcludedMimeTypes(String... types)
Set the mime types.
|
void |
setExcludedPaths(String... pathspecs) |
void |
setIncludedMethods(String... methods) |
void |
setIncludedMimeTypes(String... types)
Set included mime types.
|
void |
setIncludedPaths(String... pathspecs)
Set the path specs to include.
|
void |
setMinGzipSize(int minGzipSize)
Set the minimum response size to trigger dynamic compresssion
|
destroy, expandChildren, getHandler, getHandlers, insertHandler, setHandler
expandHandler, findContainerOf, getChildHandlerByClass, getChildHandlers, getChildHandlersByClass, setServer
doStop, dumpThis, getServer
addBean, addBean, addBean, addEventListener, addManaged, contains, dump, dump, dump, dump, dump, dumpBeans, dumpObject, dumpStdErr, getBean, getBeans, getBeans, isManaged, manage, removeBean, removeBeans, removeEventListener, setBeans, setStopTimeout, start, stop, unmanage, updateBean, updateBeans
addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addLifeCycleListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
public static final String GZIP
public static final String DEFLATE
public static final String ETAG_GZIP
public static final String ETAG
public static final int DEFAULT_MIN_GZIP_SIZE
public GzipHandler()
public void addExcludedAgentPatterns(String... patterns)
patterns
- Regular expressions matching user agents to excludepublic void addExcludedMimeTypes(String... types)
types
- The mime types to exclude (without charset or other parameters)public void addExcludedPaths(String... pathspecs)
pathspecs
- Path specs (as per servlet spec) to exclude. If a
ServletContext is available, the paths are relative to the context path,
otherwise they are absolutepublic void addIncludedMethods(String... methods)
methods
- The methods to include in compressionpublic void addIncludedMimeTypes(String... types)
types
- The mime types to include (without charset or other parameters)public void addIncludedPaths(String... pathspecs)
pathspecs
- Path specs (as per servlet spec) to include. If a
ServletContext is available, the paths are relative to the context path,
otherwise they are absolutepublic boolean getCheckGzExists()
public int getCompressionLevel()
public Deflater getDeflater(Request request, long content_length)
getDeflater
in interface GzipFactory
public String[] getExcludedAgentPatterns()
public String[] getExcludedMimeTypes()
public String[] getExcludedPaths()
public String[] getIncludedMimeTypes()
public String[] getIncludedPaths()
public String[] getMethods()
public int getMinGzipSize()
protected void doStart() throws Exception
ContainerLifeCycle
doStart
in class AbstractHandler
Exception
public void handle(String target, Request baseRequest, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws IOException, javax.servlet.ServletException
Handler
handle
in interface Handler
handle
in class HandlerWrapper
target
- The target of the request - either a URI or a name.baseRequest
- The original unwrapped request object.request
- The request either as the Request
object or a wrapper of that request. The
HttpConnection.getCurrentConnection()
.getHttpChannel()
.getRequest()
method can be used access the Request object if required.response
- The response as the Response
object or a wrapper of that request. The
HttpConnection.getCurrentConnection()
.getHttpChannel()
.getResponse()
method can be used access the Response object if required.IOException
- if unable to handle the request or response processingjavax.servlet.ServletException
- if unable to handle the request or response due to underlying servlet issueHandlerWrapper.handle(java.lang.String, org.eclipse.jetty.server.Request, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
protected boolean isExcludedAgent(String ua)
ua
- the user agentpublic boolean isMimeTypeGzipable(String mimetype)
isMimeTypeGzipable
in interface GzipFactory
protected boolean isPathGzipable(String requestURI)
requestURI
- the request uripublic void recycle(Deflater deflater)
recycle
in interface GzipFactory
public void setCheckGzExists(boolean checkGzExists)
checkGzExists
- If true, check if a static gz file exists for
the resource that the DefaultServlet may serve as precompressed.public void setCompressionLevel(int compressionLevel)
compressionLevel
- The compression level to use to initialize Deflater.setLevel(int)
public void setExcludedAgentPatterns(String... patterns)
patterns
- Regular expressions matching user agents to excludepublic void setExcludedMimeTypes(String... types)
types
- The mime types to exclude (without charset or other parameters)public void setExcludedPaths(String... pathspecs)
pathspecs
- Path specs (as per servlet spec) to exclude. If a
ServletContext is available, the paths are relative to the context path,
otherwise they are absolute.public void setIncludedMethods(String... methods)
methods
- The methods to include in compressionpublic void setIncludedMimeTypes(String... types)
types
- The mime types to include (without charset or other parameters)public void setIncludedPaths(String... pathspecs)
pathspecs
- Path specs (as per servlet spec) to include. If a
ServletContext is available, the paths are relative to the context path,
otherwise they are absolutepublic void setMinGzipSize(int minGzipSize)
minGzipSize
- minimum response size in bytesCopyright © 1995-2015 Webtide. All Rights Reserved.