public class GzipFilter
extends java.lang.Object
implements javax.servlet.Filter
Configuration is based on the following initialization parameters:
threshold
- min number of bytes for compressing
or 0 for no compression at all. By defaults is 0. Good value is 128.match
- comma separated string patterns to be found
in the uri for using gzip. Only uris that match these patterns will be gzipped.
Use '*' to enable default matching using just extensions.
extensions (ignoring the wildcards value)extensions
- when match is set to all resources,
this parameter defines list of URI extensions that should be gzipped.
By default set to: html, htm, css, js
. Use '*' to
match all extensions.
exclude
- comma separated string patterns to be excluded
if found in uri for using gzip. It is applied only if all urls are matched.wildcards
- boolean that specifies wildcard matching for string patterns.
by default false
. URL is matched as paths
.requestParameterName
- name of request parameter that can override GZipping.
Default value is gzip
. Set it to an empty string to turn this feature off.
Modifier and Type | Field and Description |
---|---|
protected java.lang.String[] |
excludes |
protected java.lang.String[] |
extensions |
protected java.lang.String[] |
matches |
protected java.lang.String |
requestParameterName |
protected int |
threshold |
protected boolean |
wildcards |
Constructor and Description |
---|
GzipFilter() |
Modifier and Type | Method and Description |
---|---|
void |
destroy() |
void |
doFilter(javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response,
javax.servlet.FilterChain chain)
If browser supports gzip, sets the Content-Encoding response header and
invoke resource with a wrapped response that collects all the output.
|
void |
init(javax.servlet.FilterConfig config)
Filter initialization.
|
protected boolean |
isGzipEligible(javax.servlet.http.HttpServletRequest request)
Determine if request is eligible for GZipping.
|
protected int threshold
protected java.lang.String[] matches
protected java.lang.String[] excludes
protected boolean wildcards
protected java.lang.String requestParameterName
protected java.lang.String[] extensions
public void doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain) throws javax.servlet.ServletException, java.io.IOException
If browser does not support gzip, invokes resource normally.
doFilter
in interface javax.servlet.Filter
javax.servlet.ServletException
java.io.IOException
public void init(javax.servlet.FilterConfig config)
init
in interface javax.servlet.Filter
public void destroy()
destroy
in interface javax.servlet.Filter
protected boolean isGzipEligible(javax.servlet.http.HttpServletRequest request)
Copyright © 2003-present Jodd Team