2012-07-30 55 views
0

我刨使用哪种传输大量的跨network.I数据对我的应用程序omnifaces已经omnifaces配置web.xml文件提及展示如下gzip的设置与omnifaces

 <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> 

荫使用卷曲测试大小,但我没有注意到任何显着的差异。 没有gzip的配置

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 

用gzip配置

 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 

你能告诉我为什么我不是上面两个命令得到什么区别?

+1

你的问题是什么? – 2012-07-30 06:22:12

+0

@LuiggiMendoza:为什么在启用'GzipResponseFilter'后他没有看到卷曲响应有任何不同。 – BalusC 2012-07-30 11:29:00

+0

@LuiggiMendoza你没有注意到我的问题:) – Suraj 2012-07-30 16:45:18

回答

2

GzipResponseFilter只在客户端支持时才返回gzip响应。这由Accept-Encoding请求标题决定。如果客户端(在你的情况下,curl)发送一个Accept-Encoding: gzip标题以及请求,那么过滤器将打开GZIP压缩来处理大于500字节的响应。

如果您在web应用中启用GzipResponseFilter之后没有看到卷曲结果有任何不同,那么显然默认情况下卷曲不会设置Accept-Encoding: gzip标头。那么你会得到“正常”的回应。您需要查阅curl文档如何设置此标题。打开全部请求的gzip压缩没有任何意义;如果客户完全不支持它,客户如何解压缩它?

顺便说一下,那两个过滤器初始化参数已经是默认值了。你可以从你的web.xml中忽略它们。只有当你想要指定不同于默认值的值时才需要指定它们。另见documentation

+0

现在使用Accept-Encoding后,我可以看到差异。谢谢你Balus – Suraj 2012-07-31 01:23:49