Jetty Logo
Version: 9.1.3-SNAPSHOT
Contact the core Jetty developers at www.webtide.com

private support for your internal/customer projects ... custom extensions and distributions ... versioned snapshots for indefinite support ... scalability guidance for your apps and Ajax/Comet projects ... development services from 1 day to full product delivery

Gzip Filter

Info
Usage
Gzip Rules
Init Parameters

Info

Usage

The Jetty GzipFilter is a compression filter that you can apply to almost any dynamic resource (servlet). It fixes many of the bugs in commonly available compression filters–for example, it handles all ways to set content length. We have tested it with Jetty continuations and suspending requests. Some user-agents might be excluded from compression to avoid common browser bugs (yes, this means IE!). See GzipFilter javadoc.

For example simply add this to your web.xml or override your web.xml using jetty'sJetty override-web.xml feature.

Gzip Rules

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.

Init Parameters

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.

bufferSize

The output buffer size which defaults to 8192. Be careful with this parameter as values <= 0 will lead to an IllegalArgumentException.

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).

deflateNoWrap

The noWrap setting for deflate compression. Defaults to true. (true/false)

methods

Comma separated list of HTTP methods to compress. If not set, only GET requests are compressed.

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.

vary

Set to the value of the Vary header sent with responses that could be compressed. By default it is set to 'Vary: 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 'Vary: Accept-Encoding'. Note also that shared caches may cache 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.

See an error or something missing? Contribute to this documentation at Github!(Generated: 2014-04-15T11:43:42-05:00)