Skip to main content
Version: 3.14.x.x LTS

DeflateFilter

The main task of the DeflateFilter is to compress the content of an HTTP response body. It uses the zlib library to perform this job. The filter is also able to measure the bandwidth of a client's connection. To do this task, it intercepts the request of the client and sends back an HTML page with some JavaScript that measures the bandwidth. The measured bandwidth is stored into a cookie. Based upon this cookie and a configured bandwidth threshold, the DeflateFilter is able to decide if compression is enabled or not. This behavior is especially useful when clients with low connection speed are expected to use the web application.

Classname
 ch::nevis::isiweb4::filter::deflate::DeflateFilter
Library
libDeflateFilter.so.1

Configuration

NameTypeUsage ConstraintsDefaultDescription
AlwaysCompressboolean: true, falseoptional, advancedfalseIf this value is set to true, bandwidth is never measured and compression is always enabled. Thus, content will always be compressed (if the client is able to read compressed content).
Used if clients are known to have slow connections or if the bandwidth measurement can confuse clients.
BandwidthThresholdintegeroptional, scaling100Defines the bandwidth threshold in KBit/s, below which compression is enabled.
Impact: CPU/Bandwidth tradeoff
DataAmountintegeroptional, advanced50000Defines the data amount, in bytes, sent to the client as bandwidth measurement is performed. A higher value results in a slower bandwidth test but more accurate measurement results.
Impact: Tradeoff between initial measurement time and cpu/bandwidth lost due to measurement error
CompressContentTypestring’text/html text/xml text/plain’Defines a list of content-types that will be compressed and permits configuration of mime types. The response will be compressed if its mime type is contained in the configured list.
CompressionLevelintegeroptional, advanced-1Defines the compression level used (0-9):
0 = no compression;
9 = maximum compression;
-1 = default compression
Impact: CPU/Bandwidth tradeoff, also depends on data.
CookieLifetimeintegeroptional, advanced0Defines the lifetime, in seconds, of the cookie set after bandwidth measurement. If the cookie expires, the bandwidth is measured again. A value of 0 means that the cookie expires if the browser is restarted. Use shorter lifetimes if you expect the bandwidth values to be around the bandwidth threshold and change often. This might be the case for wireless connections, or if multiple clients share a slow connection.
NoInterceptionPatternstringoptional, troubleshootingemptySpecifies a whitespace-separated list of URI regexps (<regexp>[) where no interception takes place. The content provider might initiate interceptions, which can get confused if bandwidth measurement is done at the same time. Set the pattern to match these locations. The default regex type is "PCRE(da)".
CompressionBufferSizeintegeroptional, advancedmin: 1024, max: unlimited, default: 4096The CompressionBufferSize directive specifies the size (in bytes) of the fragments that the zlib library should compress at one time.
CompressionMemLevelintegeroptional, advancedmin: 1, max: 9, default: 9The CompressionMemLevel parameter specifies how much memory should be allocated for the internal compression state. If CompressionMemLevel=1, the compression process uses minimum memory but is slow and reduces the compression ratio. If CompressionMemLevel=9, compression happens at optimum speed but uses maximum memory.
CompressionWindowSizeintegeroptional, advancedmin: -15, max: 15, default: -15The CompressionWindowSize parameter is the base two logarithm of the window size (the size of the history buffer). Choose a value between 8 and 15.
The CompressionWindowSize can also lie in between -8 and -15 for raw deflate. In this case, the DeflateFilter generates raw deflate data with no zlib header or trailer. It also does not compute a check value.
Be aware that some browsers are not able to decompress data compressed with a positive CompressionWindowSize.

Example

In the sample code below, the DeflateFilter compresses all responses with the specified content types into a gzip file and sends this file to the front end. The filter only compresses content with the following content types:

  • text/html
  • text/xml
  • text/plain
<filter>
<filter-name>DeflateFilter</filter-name>
<filter-class>ch::nevis::isiweb4::filter::deflate::DeflateFilter</filter-class>
<init-param>
<param-name>AlwaysCompress</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>CompressContentType</param-name>
<param-value>text/html text/xml text/plain</param-value>
</init-param>
</filter>

Place the DeflateFilter in the beginning of the filter and servlet chain (just after the front end).

note

The DeflateFilter only compresses content if the front end sends the header "Accept-Encoding: gzip". If this is not the case, the filter does not compress any response, even if the filter attribute AlwaysCompress is set to "true".

You can find the above example in examples/various/DeflateFilter.example on the installed nevisProxy package.