2012-07-30 60 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