public class GzipHandler extends HandlerWrapper
minGzipSize
initParameter or the minGzipSize is 0(default)mimeTypes
initParameter or if no mimeTypes are defined the
content-type is not "application/gzip"
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 Set<String> |
_excludedUA |
protected boolean |
_excludeMimeTypes |
protected Set<String> |
_mimeTypes |
protected int |
_minGzipSize |
protected String |
_vary |
_handler
Constructor and Description |
---|
GzipHandler()
Instantiates a new gzip handler.
|
Modifier and Type | Method and Description |
---|---|
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.
|
Set<String> |
getMimeTypes()
Get the mime types.
|
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)
Set the mime types.
|
void |
setMimeTypes(Set<String> mimeTypes)
Set the mime types.
|
void |
setMimeTypes(String mimeTypes)
Set the mime types.
|
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 boolean _excludeMimeTypes
protected int _bufferSize
protected int _minGzipSize
protected String _vary
public void setMimeTypes(Set<String> mimeTypes)
mimeTypes
- the mime types to setpublic void setMimeTypes(String mimeTypes)
mimeTypes
- the mime types to setpublic void setExcludeMimeTypes(boolean exclude)
public 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-2015 Webtide. All Rights Reserved.