org.eclipse.jetty.servlets

## Class GzipFilter

- java.lang.Object
- - org.eclipse.jetty.servlets.UserAgentFilter
  - - org.eclipse.jetty.servlets.GzipFilter

- All Implemented Interfaces:
    javax.servlet.Filter
  Direct Known Subclasses:
    IncludableGzipFilter

      public class GzipFilter
      extends UserAgentFilter

  GZIP Filter This filter will gzip or deflate the content of a response if:
  - The filter is mapped to a matching path
  - accept-encoding header is set to either gzip, deflate or a combination of those
  - 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

  If both gzip and deflate are specified in the accept-encoding header, then gzip will be used.

  Compressing the content can greatly improve the network bandwidth usage, but at a cost of memory and CPU cycles. If this filter is mapped for static content, then use of efficient direct NIO may be prevented, thus use of the gzip mechanism of the `DefaultServlet` is advised instead.

  This filter extends `UserAgentFilter` and if the the initParameter `excludedAgents` is set to a comma separated list of user agents, then these agents will be excluded from gzip content.

  Init Parameters:

       bufferSize                 The output buffer size. Defaults to 8192. Be careful as values <= 0 will lead to an
                                  IllegalArgumentException.
                                  See: GZIPOutputStream.GZIPOutputStream(java.io.OutputStream, int)
                                  and: DeflaterOutputStream.DeflaterOutputStream(java.io.OutputStream, Deflater, int)

       minGzipSize                Content will only be compressed if content length is either unknown or greater
                                  than minGzipSize.

       deflateCompressionLevel    The compression level used for deflate compression. (0-9).
                                  See: Deflater.Deflater(int, boolean)

       deflateNoWrap              The noWrap setting for deflate compression. Defaults to true. (true/false)
                                  See: Deflater.Deflater(int, boolean)

       mimeTypes                  Comma separated list of mime types to compress. See description above.

       excludedAgents             Comma separated list of user agents to exclude from compression. Does a
                                  String.contains(CharSequence) to check if the excluded agent occurs
                                  in the user-agent header. If it does -> no compression

       excludeAgentPatterns       Same as excludedAgents, but accepts regex patterns for more complex matching.

       excludePaths               Comma separated list of paths to exclude from compression.
                                  Does a String.startsWith(String) comparison to check if the path matches.
                                  If it does match -> no compression. To match subpaths use excludePathPatterns
                                  instead.

       excludePathPatterns        Same as excludePath, but accepts regex patterns for more complex matching.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected int` | `_bufferSize`
    `protected int` | `_deflateCompressionLevel`
    `protected boolean` | `_deflateNoWrap`
    `protected Set<Pattern>` | `_excludedAgentPatterns`
    `protected Set<String>` | `_excludedAgents`
    `protected Set<Pattern>` | `_excludedPathPatterns`
    `protected Set<String>` | `_excludedPaths`
    `protected Set<String>` | `_mimeTypes`
    `protected int` | `_minGzipSize`
    `static String` | `DEFLATE`
    `static String` | `GZIP`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `GzipFilter()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `configureWrappedResponse(CompressedResponseWrapper wrappedResponse)`
    `protected CompressedResponseWrapper` | `createWrappedResponse(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, String compressionType)`
    `void` | `destroy()`
    `void` | `doFilter(javax.servlet.ServletRequest req, javax.servlet.ServletResponse res, javax.servlet.FilterChain chain)`
    `void` | `init(javax.servlet.FilterConfig filterConfig)`

    - ### Methods inherited from class org.eclipse.jetty.servlets.UserAgentFilter

      `getUserAgent, getUserAgent`

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

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

- - ### Field Detail

    - #### GZIP

          public static final String GZIP

      See Also:
        Constant Field Values

    - #### DEFLATE

          public static final String DEFLATE

      See Also:
        Constant Field Values

    - #### _mimeTypes

          protected Set<String> _mimeTypes

    - #### _bufferSize

          protected int _bufferSize

    - #### _minGzipSize

          protected int _minGzipSize

    - #### _deflateCompressionLevel

          protected int _deflateCompressionLevel

    - #### _deflateNoWrap

          protected boolean _deflateNoWrap

    - #### _excludedAgents

          protected Set<String> _excludedAgents

    - #### _excludedAgentPatterns

          protected Set<Pattern> _excludedAgentPatterns

    - #### _excludedPaths

          protected Set<String> _excludedPaths

    - #### _excludedPathPatterns

          protected Set<Pattern> _excludedPathPatterns

  - ### Constructor Detail

    - #### GzipFilter

          public GzipFilter()

  - ### Method Detail

    - #### init

          public void init(javax.servlet.FilterConfig filterConfig)
                    throws javax.servlet.ServletException

      Specified by:
        `init` in interface `javax.servlet.Filter`
      Overrides:
        `init` in class `UserAgentFilter`
      Throws:
        `javax.servlet.ServletException`
      See Also:
        `UserAgentFilter.init(javax.servlet.FilterConfig)`

    - #### destroy

          public void destroy()

      Specified by:
        `destroy` in interface `javax.servlet.Filter`
      Overrides:
        `destroy` in class `UserAgentFilter`
      See Also:
        `UserAgentFilter.destroy()`

    - #### doFilter

          public void doFilter(javax.servlet.ServletRequest req,
                      javax.servlet.ServletResponse res,
                      javax.servlet.FilterChain chain)
                        throws IOException,
                               javax.servlet.ServletException

      Specified by:
        `doFilter` in interface `javax.servlet.Filter`
      Overrides:
        `doFilter` in class `UserAgentFilter`
      Throws:
        `IOException`
        `javax.servlet.ServletException`
      See Also:
        `UserAgentFilter.doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)`

    - #### createWrappedResponse

          protected CompressedResponseWrapper createWrappedResponse(javax.servlet.http.HttpServletRequest request,
                                                        javax.servlet.http.HttpServletResponse response,
                                                        String compressionType)

    - #### configureWrappedResponse

          protected void configureWrappedResponse(CompressedResponseWrapper wrappedResponse)

Copyright © 1995-2012 Mort Bay Consulting. All Rights Reserved.