public class GzipHandler extends HandlerWrapper
minGzipSize
initParameter or the minGzipSize is 0(default)true
Compressing the content can greatly improve the network bandwidth usage, but at a cost of memory and CPU cycles. If this handler is used for static content,
then use of efficient direct NIO may be prevented, thus use of the gzip mechanism of the org.eclipse.jetty.servlet.DefaultServlet
is advised instead.
AbstractLifeCycle.AbstractLifeCycleListener
LifeCycle.Listener
Container.InheritedListener, Container.Listener
Modifier and Type | Field and Description |
---|---|
protected int |
_bufferSize |
protected int |
_minGzipSize |
protected String |
_vary |
_handler
Constructor and Description |
---|
GzipHandler()
Instantiates a new gzip handler.
|
Modifier and Type | Method and Description |
---|---|
void |
addExcludedAgentPatterns(String... patterns) |
void |
addExcludedMethods(String... methods) |
void |
addExcludedMimeTypes(String... types)
Set the mime types.
|
void |
addExcludedPaths(String... pathspecs)
Add path to excluded paths list.
|
void |
addIncludedAgentPatterns(String... patterns) |
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.
|
int |
getBufferSize()
Get the buffer size.
|
Set<String> |
getExcluded()
Get the excluded user agents.
|
String[] |
getExcludedAgentPatterns() |
String[] |
getExcludedMethods() |
String[] |
getExcludedMimeTypes() |
String[] |
getExcludedPaths() |
String[] |
getIncludedAgentPatterns() |
String[] |
getIncludedMethods() |
String[] |
getIncludedMimeTypes() |
String[] |
getIncludedPaths() |
Set<String> |
getMimeTypes()
Deprecated.
use
getExcludedMimeTypes() or getIncludedMimeTypes() instead |
int |
getMinGzipSize()
Get the minimum reponse size.
|
String |
getVary() |
void |
handle(String target,
Request baseRequest,
HttpServletRequest request,
HttpServletResponse response)
Handle a request.
|
protected CompressedResponseWrapper |
newGzipResponseWrapper(HttpServletRequest request,
HttpServletResponse response)
Allows derived implementations to replace ResponseWrapper implementation.
|
protected PrintWriter |
newWriter(OutputStream out,
String encoding)
Allows derived implementations to replace PrintWriter implementation.
|
void |
setBufferSize(int bufferSize)
Set the buffer size.
|
void |
setExcluded(Set<String> excluded)
Set the excluded user agents.
|
void |
setExcluded(String excluded)
Set the excluded user agents.
|
void |
setExcludeMimeTypes(boolean exclude)
Deprecated.
use
#setExcludedMimeTypes() instead |
void |
setMimeTypes(Set<String> mimeTypes)
Deprecated.
use
#setExcludedMimeTypes() or #setIncludedMimeTypes() instead |
void |
setMimeTypes(String mimeTypes)
Deprecated.
use
#setExcludedMimeTypes() or #setIncludedMimeTypes() instead |
void |
setMinGzipSize(int minGzipSize)
Set the minimum reponse size.
|
void |
setVary(String vary)
Set the value of the Vary header sent with responses that could be compressed.
|
destroy, expandChildren, getHandler, getHandlers, setHandler, setServer
expandHandler, findContainerOf, getChildHandlerByClass, getChildHandlers, getChildHandlersByClass
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
protected int _bufferSize
protected int _minGzipSize
protected String _vary
public void addExcludedAgentPatterns(String... patterns)
patterns
- Regular expressions matching user agents to excludepublic void addExcludedMethods(String... methods)
methods
- The methods to exclude in compressionpublic 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 excludepublic 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)
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 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 absolutepublic 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 Set<String> getMimeTypes()
@Deprecated public void setMimeTypes(Set<String> mimeTypes)
#setExcludedMimeTypes()
or #setIncludedMimeTypes()
insteadmimeTypes
- the mime types to set@Deprecated public void setMimeTypes(String mimeTypes)
#setExcludedMimeTypes()
or #setIncludedMimeTypes()
insteadmimeTypes
- the mime types to set@Deprecated public void setExcludeMimeTypes(boolean exclude)
#setExcludedMimeTypes()
insteadpublic Set<String> getExcluded()
public void setExcluded(Set<String> excluded)
excluded
- excluded user agents to setpublic void setExcluded(String excluded)
excluded
- excluded user agents to setpublic String getVary()
public void setVary(String vary)
By default it is set to 'Accept-Encoding, User-Agent' since IE6 is excluded by default from the excludedAgents. If user-agents are not to be excluded, then this can be set to 'Accept-Encoding'. Note also that shared caches may cache many copies of a resource that is varied by User-Agent - one per variation of the User-Agent, unless the cache does some normalization of the UA string.
vary
- The value of the Vary header set if a response can be compressed.public int getBufferSize()
public void setBufferSize(int bufferSize)
bufferSize
- buffer size to setpublic int getMinGzipSize()
public void setMinGzipSize(int minGzipSize)
minGzipSize
- minimum reponse sizeprotected void doStart() throws Exception
ContainerLifeCycle
doStart
in class AbstractHandler
Exception
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, 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 HttpChannel.getCurrentHttpChannel()
method can be used access the Request object if required.response
- The response as the Response
object or a wrapper of that request. The HttpChannel.getCurrentHttpChannel()
method can be used access the Response object if required.IOException
ServletException
HandlerWrapper.handle(java.lang.String, org.eclipse.jetty.server.Request, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
protected CompressedResponseWrapper newGzipResponseWrapper(HttpServletRequest request, HttpServletResponse response)
request
- the requestresponse
- the responseprotected PrintWriter newWriter(OutputStream out, String encoding) throws UnsupportedEncodingException
out
- the outencoding
- the encodingUnsupportedEncodingException
Copyright © 1995-2017 Webtide. All Rights Reserved.