Question
I am planing to use omnifaces on my application which transfer large amount of data across network.I have configured web.xml file as mention in omnifaces showcase as below
<filter>
<filter-name>gzipResponseFilter</filter-name>
<filter-class>org.omnifaces.filter.GzipResponseFilter</filter-class>
<init-param>
<description>
The threshold size in bytes. Must be a number between 0 and 9999. Defaults to 500.
</description>
<param-name>threshold</param-name>
<param-value>500</param-value>
</init-param>
<init-param>
<description>
The mimetypes which needs to be compressed. Must be a commaseparated string. Defaults to the below values.
</description>
<param-name>mimetypes</param-name>
<param-value>
text/plain, text/html, text/xml, text/css, text/javascript, text/csv, text/rtf,
application/xml, application/xhtml+xml, application/javascript, application/json
</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>gzipResponseFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
Iam using curl to test the size but i didn't notice any significate difference. Without gzip configuration
curl http://localhost:8080/omnifaces-test/ > t
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1666 100 1666 0 0 126k 0 --:--:-- --:--:-- --:--:-- 147k
With gzip configuration
curl http://localhost:8080/omnifaces-test/ > t
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1666 100 1666 0 0 283k 0 --:--:-- --:--:-- --:--:-- 406k
Could you tell me why i am not getting any difference between above two command ?
Solution
The GzipResponseFilter
returns only gzipped responses when the client also supports it. This is determined by the Accept-Encoding
request header. If the client (in your case, curl) sends a Accept-Encoding: gzip
header along with the request, then the filter will turn on GZIP compression for responses larger than 500 bytes.
If you're not seeing any difference in curl results after enabling the GzipResponseFilter
in your webapp, then apparently curl does by default not set the Accept-Encoding: gzip
header. You'll get "normal" responses then. You need to consult the curl documentation how to set this header. It would not make any sense to turn on gzip compression for all requests; how would the client ever decompress it if it does after all not support it?
By the way, those two filter initialization parameters are the default values already. You can just omit them from your web.xml
. It's only necessary to specify them when you want to specify values different than the default. See also the documentation.