org.eclipse.jetty.servlets
类 GzipFilter

java.lang.Object
  继承者 org.eclipse.jetty.servlets.UserAgentFilter
      继承者 org.eclipse.jetty.servlets.GzipFilter
所有已实现的接口:
Filter
直接已知子类:
IncludableGzipFilter

public class GzipFilter
extends UserAgentFilter

GZIP Filter This filter will gzip or deflate the content of a response if:

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)

 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.
 


字段摘要
protected  int _bufferSize
           
protected  ServletContext _context
           
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> _methods
           
protected  Set<String> _mimeTypes
           
protected  int _minGzipSize
           
protected  String _vary
           
static String DEFLATE
           
static String ETAG
           
static String ETAG_DEFLATE
           
static String ETAG_GZIP
           
static String GZIP
           
 
构造方法摘要
GzipFilter()
           
 
方法摘要
protected  void configureWrappedResponse(CompressedResponseWrapper wrappedResponse)
           
protected  CompressedResponseWrapper createWrappedResponse(HttpServletRequest request, HttpServletResponse response, String compressionType)
           
 void destroy()
          Called by the web container to indicate to a filter that it is being taken out of service.
 void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
          The doFilter method of the Filter is called by the container each time a request/response pair is passed through the chain due to a client request for a resource at the end of the chain.
 void init(FilterConfig filterConfig)
          Called by the web container to indicate to a filter that it is being placed into service.
 
从类 org.eclipse.jetty.servlets.UserAgentFilter 继承的方法
getUserAgent, getUserAgent
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

字段详细信息

GZIP

public static final String GZIP
另请参见:
常量字段值

ETAG_GZIP

public static final String ETAG_GZIP
另请参见:
常量字段值

DEFLATE

public static final String DEFLATE
另请参见:
常量字段值

ETAG_DEFLATE

public static final String ETAG_DEFLATE
另请参见:
常量字段值

ETAG

public static final String ETAG
另请参见:
常量字段值

_context

protected ServletContext _context

_mimeTypes

protected Set<String> _mimeTypes

_bufferSize

protected int _bufferSize

_minGzipSize

protected int _minGzipSize

_deflateCompressionLevel

protected int _deflateCompressionLevel

_deflateNoWrap

protected boolean _deflateNoWrap

_methods

protected final Set<String> _methods

_excludedAgents

protected Set<String> _excludedAgents

_excludedAgentPatterns

protected Set<Pattern> _excludedAgentPatterns

_excludedPaths

protected Set<String> _excludedPaths

_excludedPathPatterns

protected Set<Pattern> _excludedPathPatterns

_vary

protected String _vary
构造方法详细信息

GzipFilter

public GzipFilter()
方法详细信息

init

public void init(FilterConfig filterConfig)
          throws ServletException
从接口 Filter 复制的描述
Called by the web container to indicate to a filter that it is being placed into service.

The servlet container calls the init method exactly once after instantiating the filter. The init method must complete successfully before the filter is asked to do any filtering work.

The web container cannot place the filter into service if the init method either

  1. Throws a ServletException
  2. Does not return within a time period defined by the web container

指定者:
接口 Filter 中的 init
覆盖:
UserAgentFilter 中的 init
抛出:
ServletException
另请参见:
UserAgentFilter.init(javax.servlet.FilterConfig)

destroy

public void destroy()
从接口 Filter 复制的描述
Called by the web container to indicate to a filter that it is being taken out of service.

This method is only called once all threads within the filter's doFilter method have exited or after a timeout period has passed. After the web container calls this method, it will not call the doFilter method again on this instance of the filter.

This method gives the filter an opportunity to clean up any resources that are being held (for example, memory, file handles, threads) and make sure that any persistent state is synchronized with the filter's current state in memory.

指定者:
接口 Filter 中的 destroy
覆盖:
UserAgentFilter 中的 destroy
另请参见:
UserAgentFilter.destroy()

doFilter

public void doFilter(ServletRequest req,
                     ServletResponse res,
                     FilterChain chain)
              throws IOException,
                     ServletException
从接口 Filter 复制的描述
The doFilter method of the Filter is called by the container each time a request/response pair is passed through the chain due to a client request for a resource at the end of the chain. The FilterChain passed in to this method allows the Filter to pass on the request and response to the next entity in the chain.

A typical implementation of this method would follow the following pattern:

  1. Examine the request
  2. Optionally wrap the request object with a custom implementation to filter content or headers for input filtering
  3. Optionally wrap the response object with a custom implementation to filter content or headers for output filtering
    • Either invoke the next entity in the chain using the FilterChain object (chain.doFilter()),
    • or not pass on the request/response pair to the next entity in the filter chain to block the request processing
  4. Directly set headers on the response after invocation of the next entity in the filter chain.

指定者:
接口 Filter 中的 doFilter
覆盖:
UserAgentFilter 中的 doFilter
抛出:
IOException
ServletException
另请参见:
UserAgentFilter.doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)

createWrappedResponse

protected CompressedResponseWrapper createWrappedResponse(HttpServletRequest request,
                                                          HttpServletResponse response,
                                                          String compressionType)

configureWrappedResponse

protected void configureWrappedResponse(CompressedResponseWrapper wrappedResponse)


Copyright © 2013. All Rights Reserved.