You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by re...@apache.org on 2022/04/11 11:14:38 UTC

[tomcat] branch main updated: PR501: Add header size attributes

This is an automated email from the ASF dual-hosted git repository.

remm pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/main by this push:
     new 6cdd999e65 PR501: Add header size attributes
6cdd999e65 is described below

commit 6cdd999e652ad122781164172c1d7f9b175a6446
Author: remm <re...@apache.org>
AuthorDate: Mon Apr 11 13:14:17 2022 +0200

    PR501: Add header size attributes
    
    Add new maxHttpRequestHeaderSize and maxHttpResponseHeaderSize
    attributes which allow setting the maximum HTTP header sizes
    independently. If not specified, the value of the maxHttpHeaderSize
    connector attribute will be used.
    Added documentation.
    HTTP/2 should use maxHttpRequestHeaderSize and inherit it, while
    maxHttpResponseHeaderSize will do nothing.
    Submitted by Zhongming Hua.
---
 .../coyote/http11/AbstractHttp11Protocol.java      | 28 ++++++++++++++++++++++
 java/org/apache/coyote/http11/Http11Processor.java |  4 ++--
 java/org/apache/coyote/http2/Http2Protocol.java    |  2 +-
 webapps/docs/changelog.xml                         | 11 +++++++++
 webapps/docs/config/http.xml                       | 12 ++++++++++
 webapps/docs/config/http2.xml                      |  1 +
 6 files changed, 55 insertions(+), 3 deletions(-)

diff --git a/java/org/apache/coyote/http11/AbstractHttp11Protocol.java b/java/org/apache/coyote/http11/AbstractHttp11Protocol.java
index 10512660c4..1a88c314a0 100644
--- a/java/org/apache/coyote/http11/AbstractHttp11Protocol.java
+++ b/java/org/apache/coyote/http11/AbstractHttp11Protocol.java
@@ -244,6 +244,34 @@ public abstract class AbstractHttp11Protocol<S> extends AbstractProtocol<S> {
     public void setMaxHttpHeaderSize(int valueI) { maxHttpHeaderSize = valueI; }
 
 
+    /**
+     * Maximum size of the HTTP request message header.
+     */
+    private int maxHttpRequestHeaderSize = -1;
+
+    public int getMaxHttpRequestHeaderSize() {
+        return maxHttpRequestHeaderSize == -1 ? getMaxHttpHeaderSize() : maxHttpRequestHeaderSize;
+    }
+
+    public void setMaxHttpRequestHeaderSize(int valueI) {
+        maxHttpRequestHeaderSize = valueI;
+    }
+
+
+    /**
+     * Maximum size of the HTTP response message header.
+     */
+    private int maxHttpResponseHeaderSize = -1;
+
+    public int getMaxHttpResponseHeaderSize() {
+        return maxHttpResponseHeaderSize == -1 ? getMaxHttpHeaderSize() : maxHttpResponseHeaderSize;
+    }
+
+    public void setMaxHttpResponseHeaderSize(int valueI) {
+        maxHttpResponseHeaderSize = valueI;
+    }
+
+
     private int connectionUploadTimeout = 300000;
     /**
      * Specifies a different (usually longer) connection timeout during data
diff --git a/java/org/apache/coyote/http11/Http11Processor.java b/java/org/apache/coyote/http11/Http11Processor.java
index 4f8261362e..c4be0ede8d 100644
--- a/java/org/apache/coyote/http11/Http11Processor.java
+++ b/java/org/apache/coyote/http11/Http11Processor.java
@@ -159,11 +159,11 @@ public class Http11Processor extends AbstractProcessor {
         httpParser = new HttpParser(protocol.getRelaxedPathChars(),
                 protocol.getRelaxedQueryChars());
 
-        inputBuffer = new Http11InputBuffer(request, protocol.getMaxHttpHeaderSize(),
+        inputBuffer = new Http11InputBuffer(request, protocol.getMaxHttpRequestHeaderSize(),
                 protocol.getRejectIllegalHeader(), httpParser);
         request.setInputBuffer(inputBuffer);
 
-        outputBuffer = new Http11OutputBuffer(response, protocol.getMaxHttpHeaderSize());
+        outputBuffer = new Http11OutputBuffer(response, protocol.getMaxHttpResponseHeaderSize());
         response.setOutputBuffer(outputBuffer);
 
         // Create and add the identity filters.
diff --git a/java/org/apache/coyote/http2/Http2Protocol.java b/java/org/apache/coyote/http2/Http2Protocol.java
index 7bdc6cb648..9df4e9f06c 100644
--- a/java/org/apache/coyote/http2/Http2Protocol.java
+++ b/java/org/apache/coyote/http2/Http2Protocol.java
@@ -262,7 +262,7 @@ public class Http2Protocol implements UpgradeProtocol {
 
 
     public int getMaxHeaderSize() {
-        return http11Protocol.getMaxHttpHeaderSize();
+        return http11Protocol.getMaxHttpRequestHeaderSize();
     }
 
 
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 0540db1f1c..dab30fb302 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -114,6 +114,17 @@
       </fix>
     </changelog>
   </subsection>
+  <subsection name="Coyote">
+    <changelog>
+      <add>
+        <pr>501</pr>: Add new <code>maxHttpRequestHeaderSize</code> and
+        <code>maxHttpResponseHeaderSize</code> attributes which allow setting
+        the maximum HTTP header sizes independently. If not specified, the
+        value of the <code>maxHttpHeaderSize</code> connector attribute will
+        be used. Submitted by Zhongming Hua. (remm)
+      </add>
+    </changelog>
+  </subsection>
 </section>
 <section name="Tomcat 10.1.0-M14 (markt)" rtext="2022-04-01">
   <subsection name="Catalina">
diff --git a/webapps/docs/config/http.xml b/webapps/docs/config/http.xml
index 6ddf476be2..ea10297737 100644
--- a/webapps/docs/config/http.xml
+++ b/webapps/docs/config/http.xml
@@ -512,6 +512,18 @@
       in bytes. If not specified, this attribute is set to 8192 (8 KB).</p>
     </attribute>
 
+    <attribute name="maxHttpRequestHeaderSize" required="false">
+      <p>The maximum size of the request HTTP header, specified
+      in bytes. If not specified, this attribute is set to the value of
+      the <code>maxHttpHeaderSize</code> attribute.</p>
+    </attribute>
+
+    <attribute name="maxHttpResponseHeaderSize" required="false">
+      <p>The maximum size of the response HTTP header, specified
+      in bytes. If not specified, this attribute is set to the value of
+      the <code>maxHttpHeaderSize</code> attribute.</p>
+    </attribute>
+
     <attribute name="maxKeepAliveRequests" required="false">
       <p>The maximum number of HTTP requests which can be pipelined until
       the connection is closed by the server. Setting this attribute to 1 will
diff --git a/webapps/docs/config/http2.xml b/webapps/docs/config/http2.xml
index b6172ff797..9adacb1d2d 100644
--- a/webapps/docs/config/http2.xml
+++ b/webapps/docs/config/http2.xml
@@ -217,6 +217,7 @@
     <li>compressionMinSize</li>
     <li>maxCookieCount</li>
     <li>maxHttpHeaderSize</li>
+    <li>maxHttpRequestHeaderSize</li>
     <li>maxParameterCount</li>
     <li>maxPostSize</li>
     <li>maxSavePostSize</li>


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org