一、計算上限值重要注意事項,若系統需使用大量參數時,,需注意其大小或長度上限值,避免系統無法正常運作

1.瀏覽器有不同的參數長度最大上限值。

   (1)Microsoft Internet Explorer 最大uniform resource locator(URL)長度為 2083 字元,對於POST(計算Header)與GET(計算URL)方法,實際可用最路徑大長度為 2048 字元。

      https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer

   (2)Firefox 至少 65536 字元。

       https://www.boutell.com/newfaq/misc/urllength.html

   (3)Chrome 未明確限制。

   (4)Safari至少 80000 字元。

       https://www.boutell.com/newfaq/misc/urllength.html

   (5)Opera至少 19000 字元。

       https://www.boutell.com/newfaq/misc/urllength.html

   (3)其它
       https://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url-in-different-browsers

2.網頁伺服器對於包含與未包含參數的URL處理,有不同的上限值。

   (1)URI長度超過限制

       https://tools.ietf.org/html/rfc2616#section-10.4.15

   (2)IIS伺服器使用maxQueryString控制查詢參數長度,未設定則預設為 2048 字元;使用maxUrl控置網指路徑長度,未設定則預設為 4096 字元。

      https://docs.microsoft.com/en-us/iis/configuration/system.webserver/security/requestfiltering/requestlimits/

   (3)httpd Apache使用LimitRequestLine控制查詢參數長度,未設定則預設為 8190 字元。

       http://httpd.apache.org/docs/2.2/mod/core.html#limitrequestline

   (4)Apache Tomcat使用maxHttpHeaderSize控制查詢參數長度,未設定則預設為 8192 字元。

   (5)Perl Http::Daemon 至少 8000 字元還可以運作。

       https://www.boutell.com/newfaq/misc/urllength.html

   (6)ngix下列參數控制參數大小

        

Syntax: client_header_buffer_size size;
Default:
client_header_buffer_size 1k;
Context: http, server

 

Syntax: large_client_header_buffers number size;
Default:
large_client_header_buffers 4 8k;
Context: http, server

        http://nginx.org/en/docs/http/ngx_http_core_module.html

3.通常許多伺服器或瀏覽器的長度上限值計算,常常包含URL與其後所帶有的參數(URI)一併列入計算。

4.URI、URL、URN、Query String的定義與不同

   (1)URI定義:https://en.wikipedia.org/wiki/Uniform_Resource_Identifier

       https://tools.ietf.org/html/rfc3986#section-1.1

   (2)URL定義:https://en.wikipedia.org/wiki/URL

       https://tools.ietf.org/html/rfc2616#section-3.2.2

   (3)URN定義:https://en.wikipedia.org/wiki/Uniform_Resource_Name

   (4)Query String定義:https://en.wikipedia.org/wiki/Query_string

      https://tools.ietf.org/html/rfc3986#section-3.4

   (5)URI、URL和URN關聯

      https://tools.ietf.org/html/rfc3986#section-1.1.3

      https://www.ibm.com/developerworks/cn/xml/x-urlni.html

5.Http協定未定義URI長度限制

   https://tools.ietf.org/html/rfc2616#section-3.2.1

The HTTP protocol does not place any a priori limit on the length of
   a URI. Servers MUST be able to handle the URI of any resource they
   serve, and SHOULD be able to handle URIs of unbounded length if they
   provide GET-based forms that could generate such URIs. A server
   SHOULD return 414 (Request-URI Too Long) status if a URI is longer
   than the server can handle (see section 10.4.15).

      Note: Servers ought to be cautious about depending on URI lengths
      above 255 bytes, because some older client or proxy
      implementations might not properly support these lengths.

二、重要注意事項

1.由上列資訊得知,為了兼容眾多瀏覽器,網址與參數長度大小最好限制在 2048 字元以下。

2.避免眾多網頁伺服器未調整參數數量與參數值,網址與參數長度大小最好限制在 2048 字元以下。

三、常見伺服器參數值相關設定方法:

1.伺服器:Apache Tomcat 8.5,設定參數檔位置在$CATALINA_HOME\conf\server.xml中

參數設定說明文件

(1)maxHeaderCount:使用request中可包含的Header數量,未指定此參數時,預設為100個,若設定為0則不限制。

(2)maxParameterCount:GET + POST中可包含參數數量,未指定此參數時,預設為10000個,若設定為0則不限制。

(3)maxPostSize:POST方法可傳送的資料大小,未設定則預設為2097152(2 megabytes)。

(4)maxHttpHeaderSize:request、response的Http header長度最大值,未設定此參數時,預設為8192(8 kb)。

設定情境範例:
(1)Tomcat伺服器連線埠號為8080。使用org
(2)使用org.apache.coyote.http11.Http11Nio2Protocol協定。
(3)request中可包含的Header數量設定為200個-->maxHeaderCount="200"
(4)GET + POST中可包含參數數量設定為500個-->maxParameterCount="500"
(5)POST方法可傳送的資料大小設定20971520(20 MB)
(6)Http header長度最大值設定為81920 (80 KB)
<Connector port="8080" protocol="org.apache.coyote.http11.Http11Nio2Protocol" maxHeaderCount="200" maxParameterCount="500" maxPostSize="20971520" maxHttpHeaderSize="81920" />

 

 

參考資料來源:

https://github.com/zhongxia245/blog/issues/35

https://tools.ietf.org/html/rfc2616

https://tools.ietf.org/html/rfc3986

 

arrow
arrow

    K 發表在 痞客邦 留言(0) 人氣()