+49 228 5552576-0
info@predic8.com

2Way HTTP Compression Servlet Filter

2Way compression filter is a Servlet filter that compresses and decompresses both HTTP requests and HTTP responses using gzip. It was originally written to compress SOAP messages, but it can be used for any Web application running in a J2EE Web container like Jetty, JRun or Tomcat.

HTTP compression can drastically reduce download time. Most Web servers and Web containers have built-in support for HTTP compression. If not, servlet filters can be used. Most of the solutions only compress the HTTP response which is fine for Web browsing where the request consists of just a few bytes. The situation is different if HTTP is used to transport SOAP messages because the average SOAP request message is the same size as the average SOAP response. To get the most out of HTTP compression, the request should also be compressed.

How it Works

Server and client negotiate about compression using HTTP header fields.

Decompressing Requests

If a request is compressed a Content-Encoding header is added to the HTTP header fields. The value of this field indicates the compression algorithm. The filter decompresses a request if it finds a Content-Encoding header field.

GET /products/firefox/start/ HTTP/1.1
Host: www.mozilla.org
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7) 
Accept: text/xml,application/xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.5

Accept-Encoding: gzip,deflate

Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7

Content-Encoding: gzip

Keep-Alive: 300
Connection: keep-alive

Compressing Responses

The response is only compressed if the client is able to decompress it. The client tells the server about its ability to decompress in the response's Accept-Encoding header field. The client in the example is accepting compressed responses using gzip and deflate.

Installation

It is easy to use the filter in your own program without changing source code. To use the filter with a Web application, these steps have to be followed:

License

Use of this software is free of charge for both personal and commercial purposes.

predic8 HEREBY DISCLAIMS ANY AND ALL WARRANTIES, EXPRESS OR IMPLIED, RELATIVE TO THE SOFTWARE, INCLUDING BUT NOT LIMITED TO ANY WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR MERCHANTIBILITY. predic8 SHALL NOT BE LIABLE OR RESPONSIBLE FOR ANY DAMAGES, INJURIES OR LIABILITIES CAUSED DIRECTLY OR INDIRECTLY FROM THE USE OF THE SOFTWARE, INCLUDING BUT NOT LIMITED TO INCIDENTAL, CONSEQUENTIAL OR SPECIAL DAMAGES.

Share