Handler
, GzipFactory
, HandlerContainer
, org.eclipse.jetty.util.component.Destroyable
, org.eclipse.jetty.util.component.LifeCycle
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.ErrorDispatchHandler
org.eclipse.jetty.util.component.AbstractLifeCycle.AbstractLifeCycleListener
Modifier and Type | Field | Description |
---|---|---|
static int |
DEFAULT_MIN_GZIP_SIZE |
|
static java.lang.String |
DEFLATE |
|
static java.lang.String |
GZIP |
FAILED, RUNNING, STARTED, STARTING, STOPPED, STOPPING
_handler
Constructor | Description |
---|---|
GzipHandler() |
Instantiates a new gzip handler.
|
Modifier and Type | Method | Description |
---|---|---|
void |
addExcludedAgentPatterns(java.lang.String... patterns) |
|
void |
addExcludedMethods(java.lang.String... methods) |
|
void |
addExcludedMimeTypes(java.lang.String... types) |
Set the mime types.
|
void |
addExcludedPaths(java.lang.String... pathspecs) |
Add path to excluded paths list.
|
void |
addIncludedAgentPatterns(java.lang.String... patterns) |
|
void |
addIncludedMethods(java.lang.String... methods) |
|
void |
addIncludedMimeTypes(java.lang.String... types) |
Add included mime types.
|
void |
addIncludedPaths(java.lang.String... pathspecs) |
Add path specs to include.
|
protected void |
doStart() |
|
boolean |
getCheckGzExists() |
|
int |
getCompressionLevel() |
|
java.util.zip.Deflater |
getDeflater(Request request,
long content_length) |
|
java.lang.String[] |
getExcludedAgentPatterns() |
|
java.lang.String[] |
getExcludedMethods() |
|
java.lang.String[] |
getExcludedMimeTypes() |
|
java.lang.String[] |
getExcludedPaths() |
|
java.lang.String[] |
getIncludedAgentPatterns() |
|
java.lang.String[] |
getIncludedMethods() |
|
java.lang.String[] |
getIncludedMimeTypes() |
|
java.lang.String[] |
getIncludedPaths() |
|
int |
getInflateBufferSize() |
|
java.lang.String[] |
getMethods() |
Deprecated.
|
int |
getMinGzipSize() |
Get the minimum response size.
|
protected org.eclipse.jetty.http.HttpField |
getVaryField() |
|
void |
handle(java.lang.String target,
Request baseRequest,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response) |
Handle a request.
|
protected boolean |
isAgentGzipable(java.lang.String ua) |
Checks to see if the userAgent is excluded
|
boolean |
isMimeTypeGzipable(java.lang.String mimetype) |
|
protected boolean |
isPathGzipable(java.lang.String requestURI) |
Checks to see if the path is included or not excluded
|
boolean |
isSyncFlush() |
|
void |
recycle(java.util.zip.Deflater deflater) |
|
void |
setCheckGzExists(boolean checkGzExists) |
|
void |
setCompressionLevel(int compressionLevel) |
|
void |
setExcludedAgentPatterns(java.lang.String... patterns) |
|
void |
setExcludedMethods(java.lang.String... method) |
|
void |
setExcludedMimeTypes(java.lang.String... types) |
Set the mime types.
|
void |
setExcludedPaths(java.lang.String... pathspecs) |
|
void |
setIncludedAgentPatterns(java.lang.String... patterns) |
|
void |
setIncludedMethods(java.lang.String... methods) |
|
void |
setIncludedMimeTypes(java.lang.String... types) |
Set included mime types.
|
void |
setIncludedPaths(java.lang.String... pathspecs) |
Set the path specs to include.
|
void |
setInflateBufferSize(int size) |
|
void |
setMinGzipSize(int minGzipSize) |
Set the minimum response size to trigger dynamic compresssion
|
void |
setSyncFlush(boolean syncFlush) |
Set the
Deflater flush mode to use. |
doError, doStop, dumpThis, getServer
expandHandler, findContainerOf, getChildHandlerByClass, getChildHandlers, getChildHandlersByClass, setServer
addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
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, updateBean, updateBeans
destroy, expandChildren, getHandler, getHandlers, insertHandler, setHandler
public static final java.lang.String GZIP
public static final java.lang.String DEFLATE
public static final int DEFAULT_MIN_GZIP_SIZE
public GzipHandler()
public void addExcludedAgentPatterns(java.lang.String... patterns)
patterns
- Regular expressions matching user agents to excludepublic void addExcludedMethods(java.lang.String... methods)
methods
- The methods to exclude in compressionpublic void addExcludedMimeTypes(java.lang.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(java.lang.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(java.lang.String... patterns)
patterns
- Regular expressions matching user agents to excludepublic void addIncludedMethods(java.lang.String... methods)
methods
- The methods to include in compressionpublic boolean isSyncFlush()
Deflater.SYNC_FLUSH
is used, else Deflater.NO_FLUSH
public 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_FLUSH
public void addIncludedMimeTypes(java.lang.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(java.lang.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 include. If a
ServletContext is available, the paths are relative to the context path,
otherwise they are absoluteprotected void doStart() throws java.lang.Exception
doStart
in class AbstractHandler
java.lang.Exception
public boolean getCheckGzExists()
public int getCompressionLevel()
public java.util.zip.Deflater getDeflater(Request request, long content_length)
getDeflater
in interface GzipFactory
public java.lang.String[] getExcludedAgentPatterns()
public java.lang.String[] getExcludedMethods()
public java.lang.String[] getExcludedMimeTypes()
public java.lang.String[] getExcludedPaths()
public java.lang.String[] getIncludedAgentPatterns()
public java.lang.String[] getIncludedMethods()
public java.lang.String[] getIncludedMimeTypes()
public java.lang.String[] getIncludedPaths()
@Deprecated public java.lang.String[] getMethods()
public int getMinGzipSize()
protected org.eclipse.jetty.http.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(java.lang.String target, Request baseRequest, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws java.io.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.java.io.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 isAgentGzipable(java.lang.String ua)
ua
- the user agentpublic boolean isMimeTypeGzipable(java.lang.String mimetype)
isMimeTypeGzipable
in interface GzipFactory
protected boolean isPathGzipable(java.lang.String requestURI)
requestURI
- the request uripublic void recycle(java.util.zip.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(java.lang.String... patterns)
patterns
- Regular expressions matching user agents to excludepublic void setExcludedMethods(java.lang.String... method)
method
- to excludepublic void setExcludedMimeTypes(java.lang.String... types)
types
- The mime types to exclude (without charset or other parameters)public void setExcludedPaths(java.lang.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(java.lang.String... patterns)
patterns
- Regular expressions matching user agents to includepublic void setIncludedMethods(java.lang.String... methods)
methods
- The methods to include in compressionpublic void setIncludedMimeTypes(java.lang.String... types)
types
- The mime types to include (without charset or other parameters)public void setIncludedPaths(java.lang.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–2018 Webtide. All rights reserved.