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.
AbstractHandler.ErrorDispatchHandlerAbstractLifeCycle.AbstractLifeCycleListenerLifeCycle.ListenerContainer.InheritedListener, Container.Listener| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_MIN_GZIP_SIZE |
static String |
DEFLATE |
static String |
GZIP |
_handlerFAILED, RUNNING, STARTED, STARTING, STOP_ON_FAILURE, STOPPED, STOPPING| Constructor and Description |
|---|
GzipHandler()
Instantiates a new gzip handler.
|
destroy, expandChildren, getHandler, getHandlers, insertHandler, setHandlerexpandHandler, findContainerOf, getChildHandlerByClass, getChildHandlers, getChildHandlersByClass, setServerdoError, doStop, dumpThis, getServeraddBean, 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, updateBean, updateBeansaddLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stopclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitaddLifeCycleListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, start, stop, stoppublic static final String GZIP
public static final String DEFLATE
public static final int DEFAULT_MIN_GZIP_SIZE
public GzipHandler()
public void addExcludedAgentPatterns(String... patterns)
patterns - Regular expressions matching user agents to excludepublic void addExcludedMethods(String... methods)
methods - The methods to exclude in compressionpublic EnumSet<DispatcherType> getDispatcherTypes()
public void setDispatcherTypes(EnumSet<DispatcherType> dispatchers)
public void setDispatcherTypes(DispatcherType... dispatchers)
public void addExcludedMimeTypes(String... types)
types - The mime types to exclude (without charset or other parameters).
For backward compatibility the mimetypes may be comma separated strings, but this
will not be supported in future versions.public void addExcludedPaths(String... pathspecs)
There are 2 syntaxes supported, Servlet url-pattern based, and
Regex based. This means that the initial characters on the path spec
line are very strict, and determine the behavior of the path matching.
'^' the spec is assumed to be
a regex based path spec and will match with normal Java regex rules.'/' then spec is assumed to be
a Servlet url-pattern rules path spec for either an exact match
or prefix based match.'*.' then spec is assumed to be
a Servlet url-pattern rules path spec for a suffix based match.Note: inclusion takes precedence over exclude.
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 addIncludedAgentPatterns(String... patterns)
patterns - Regular expressions matching user agents to includepublic void addIncludedMethods(String... methods)
methods - The methods to include in compressionpublic boolean isSyncFlush()
Deflater.SYNC_FLUSH is used, else Deflater.NO_FLUSHpublic void setSyncFlush(boolean syncFlush)
Set the Deflater flush mode to use. Deflater.SYNC_FLUSH
should be used if the application wishes to stream the data, but this may
hurt compression performance.
syncFlush - True if Deflater.SYNC_FLUSH is used, else Deflater.NO_FLUSHpublic void addIncludedMimeTypes(String... types)
types - The mime types to include (without charset or other parameters)
For backward compatibility the mimetypes may be comma separated strings, but this
will not be supported in future versions.public void addIncludedPaths(String... pathspecs)
There are 2 syntaxes supported, Servlet url-pattern based, and
Regex based. This means that the initial characters on the path spec
line are very strict, and determine the behavior of the path matching.
'^' the spec is assumed to be
a regex based path spec and will match with normal Java regex rules.'/' then spec is assumed to be
a Servlet url-pattern rules path spec for either an exact match
or prefix based match.'*.' then spec is assumed to be
a Servlet url-pattern rules path spec for a suffix based match.Note: inclusion takes precedence over exclusion.
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 absoluteprotected void doStart()
throws Exception
doStart in class AbstractHandlerExceptionpublic boolean getCheckGzExists()
public int getCompressionLevel()
public Deflater getDeflater(Request request, long content_length)
getDeflater in interface GzipFactorypublic String[] getExcludedAgentPatterns()
public String[] getExcludedMethods()
public String[] getExcludedMimeTypes()
public String[] getExcludedPaths()
public String[] getIncludedAgentPatterns()
public String[] getIncludedMethods()
public String[] getIncludedMimeTypes()
public String[] getIncludedPaths()
@Deprecated public String[] getMethods()
public int getMinGzipSize()
protected HttpField getVaryField()
public int getInflateBufferSize()
public void setInflateBufferSize(int size)
size - size in bytes of the buffer to inflate compressed request, or 0 for no inflation.public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
Handlerhandle in interface Handlerhandle in class HandlerWrappertarget - 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 processingServletException - if unable to handle the request or response due to underlying servlet issueprotected boolean isAgentGzipable(String ua)
ua - the user agentpublic boolean isMimeTypeGzipable(String mimetype)
isMimeTypeGzipable in interface GzipFactoryprotected boolean isPathGzipable(String requestURI)
requestURI - the request uripublic void recycle(Deflater deflater)
recycle in interface GzipFactorypublic void setCheckGzExists(boolean checkGzExists)
checkGzExists - whether to 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 setExcludedMethods(String... methods)
methods - the HTTP methods 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 setIncludedAgentPatterns(String... patterns)
patterns - Regular expressions matching user agents to includepublic 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 bytespublic void setIncludedMethodList(String csvMethods)
public String getIncludedMethodList()
public void setExcludedMethodList(String csvMethods)
public String getExcludedMethodList()
Copyright © 1995–2017 Webtide. All rights reserved.