org.eclipse.jetty.server.handler

## Class GzipHandler

- java.lang.Object
- - org.eclipse.jetty.util.component.AbstractLifeCycle
  - - org.eclipse.jetty.util.component.AggregateLifeCycle
    - - org.eclipse.jetty.server.handler.AbstractHandler
      - - org.eclipse.jetty.server.handler.AbstractHandlerContainer
        - - org.eclipse.jetty.server.handler.HandlerWrapper
          - - org.eclipse.jetty.server.handler.GzipHandler

All Implemented Interfaces:
  Handler, HandlerContainer, Destroyable, Dumpable, LifeCycle

    public class GzipHandler
    extends HandlerWrapper

GZIP Handler This handler will gzip the content of a response if:

- The filter is mapped to a matching path
- The response status code is >=200 and <300
- The content length is unknown or more than the `minGzipSize` initParameter or the minGzipSize is 0(default)
- The content-type is in the comma separated list of mimeTypes set in the `mimeTypes` initParameter or if no mimeTypes are defined the content-type is not "application/gzip"
- No content-encoding is specified by the resource

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.

### Nested Class Summary

### Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle

`AbstractLifeCycle.AbstractLifeCycleListener`

### Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycle

`LifeCycle.Listener`

### Field Summary

Fields
`protected int` `_bufferSize`
`protected Set<String>` `_excluded`
`protected Set<String>` `_mimeTypes`
`protected int` `_minGzipSize`
`protected String` `_vary`

### Fields inherited from class org.eclipse.jetty.server.handler.HandlerWrapper

`_handler`

### Fields inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle

`_listeners, FAILED, RUNNING, STARTED, STARTING, STOPPED, STOPPING`

### Constructor Summary

Constructors
Constructor and Description
`GzipHandler()` Instantiates a new gzip handler.

### Method Summary

Methods
`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, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)` Handle a request.
`protected CompressedResponseWrapper` `newGzipResponseWrapper(javax.servlet.http.HttpServletRequest request, javax.servlet.http.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` `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.

### Methods inherited from class org.eclipse.jetty.server.handler.HandlerWrapper

`destroy, doStart, doStop, expandChildren, getHandler, getHandlers, getNestedHandlerByClass, setHandler, setServer`

### Methods inherited from class org.eclipse.jetty.server.handler.AbstractHandlerContainer

`dump, expandHandler, findContainerOf, getChildHandlerByClass, getChildHandlers, getChildHandlersByClass`

### Methods inherited from class org.eclipse.jetty.server.handler.AbstractHandler

`dumpThis, getServer`

### Methods inherited from class org.eclipse.jetty.util.component.AggregateLifeCycle

`addBean, addBean, contains, dump, dump, dump, dump, dumpObject, dumpStdErr, getBean, getBeans, getBeans, isManaged, manage, removeBean, removeBeans, unmanage`

### Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle

`addLifeCycleListener, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface org.eclipse.jetty.util.component.LifeCycle

`addLifeCycleListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop`

### Field Detail

#### _mimeTypes

    protected Set<String> _mimeTypes

#### _excluded

    protected Set<String> _excluded

#### _bufferSize

    protected int _bufferSize

#### _minGzipSize

    protected int _minGzipSize

#### _vary

    protected String _vary

### Constructor Detail

#### GzipHandler

    public GzipHandler()

Instantiates a new gzip handler.

### Method Detail

#### getMimeTypes

    public Set<String> getMimeTypes()

Get the mime types.

Returns:
  mime types to set

#### setMimeTypes

    public void setMimeTypes(Set<String> mimeTypes)

Set the mime types.

Parameters:
  `mimeTypes` - the mime types to set

#### setMimeTypes

    public void setMimeTypes(String mimeTypes)

Set the mime types.

Parameters:
  `mimeTypes` - the mime types to set

#### getExcluded

    public Set<String> getExcluded()

Get the excluded user agents.

Returns:
  excluded user agents

#### setExcluded

    public void setExcluded(Set<String> excluded)

Set the excluded user agents.

Parameters:
  `excluded` - excluded user agents to set

#### setExcluded

    public void setExcluded(String excluded)

Set the excluded user agents.

Parameters:
  `excluded` - excluded user agents to set

#### getVary

    public String getVary()

Returns:
  The value of the Vary header set if a response can be compressed.

#### setVary

    public void setVary(String vary)

Set the value of the Vary header sent with responses that could be compressed.

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.

Parameters:
  `vary` - The value of the Vary header set if a response can be compressed.

#### getBufferSize

    public int getBufferSize()

Get the buffer size.

Returns:
  the buffer size

#### setBufferSize

    public void setBufferSize(int bufferSize)

Set the buffer size.

Parameters:
  `bufferSize` - buffer size to set

#### getMinGzipSize

    public int getMinGzipSize()

Get the minimum reponse size.

Returns:
  minimum reponse size

#### setMinGzipSize

    public void setMinGzipSize(int minGzipSize)

Set the minimum reponse size.

Parameters:
  `minGzipSize` - minimum reponse size

#### handle

    public void handle(String target,
              Request baseRequest,
              javax.servlet.http.HttpServletRequest request,
              javax.servlet.http.HttpServletResponse response)
                throws IOException,
                       javax.servlet.ServletException

Description copied from interface: `Handler`
Handle a request.

Specified by:
  `handle` in interface `Handler`
Overrides:
  `handle` in class `HandlerWrapper`
Parameters:
  `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 `AbstractHttpConnection.getCurrentConnection()` method can be used access the Request object if required.
  `response` - The response as the `Response` object or a wrapper of that request. The `AbstractHttpConnection.getCurrentConnection()` method can be used access the Response object if required.
Throws:
  `IOException`
  `javax.servlet.ServletException`
See Also:
  `HandlerWrapper.handle(java.lang.String, org.eclipse.jetty.server.Request, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)`

#### newGzipResponseWrapper

    protected CompressedResponseWrapper newGzipResponseWrapper(javax.servlet.http.HttpServletRequest request,
                                                   javax.servlet.http.HttpServletResponse response)

Allows derived implementations to replace ResponseWrapper implementation.

Parameters:
  `request` - the request
  `response` - the response
Returns:
  the gzip response wrapper

#### newWriter

    protected PrintWriter newWriter(OutputStream out,
                        String encoding)
                             throws UnsupportedEncodingException

Allows derived implementations to replace PrintWriter implementation.

Parameters:
  `out` - the out
  `encoding` - the encoding
Returns:
  the prints the writer
Throws:
  `UnsupportedEncodingException`