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

markt pushed a commit to branch 10.1.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit 4aa508f0f1b9eea08bf8eb812eb7de35db91e986
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Tue Jul 23 15:10:52 2024 +0100

    Create an HttpParser per Protocol rather than per Processor
    
    Parser configuration depends on Protocol so this reduces the number of
    HttpParser instances created. Particularly helpful for HTTP/2 which does
    not recycle Processors.
---
 java/org/apache/coyote/http11/AbstractHttp11Protocol.java | 9 +++++++++
 java/org/apache/coyote/http11/Http11Processor.java        | 9 ++-------
 java/org/apache/coyote/http2/StreamProcessor.java         | 3 +--
 webapps/docs/changelog.xml                                | 5 +++++
 4 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/java/org/apache/coyote/http11/AbstractHttp11Protocol.java 
b/java/org/apache/coyote/http11/AbstractHttp11Protocol.java
index e6fa58663d..561e6d322d 100644
--- a/java/org/apache/coyote/http11/AbstractHttp11Protocol.java
+++ b/java/org/apache/coyote/http11/AbstractHttp11Protocol.java
@@ -45,6 +45,7 @@ import org.apache.coyote.http11.upgrade.UpgradeGroupInfo;
 import org.apache.coyote.http11.upgrade.UpgradeProcessorExternal;
 import org.apache.coyote.http11.upgrade.UpgradeProcessorInternal;
 import org.apache.tomcat.util.buf.StringUtils;
+import org.apache.tomcat.util.http.parser.HttpParser;
 import org.apache.tomcat.util.modeler.Registry;
 import org.apache.tomcat.util.modeler.Util;
 import org.apache.tomcat.util.net.AbstractEndpoint;
@@ -58,6 +59,7 @@ public abstract class AbstractHttp11Protocol<S> extends 
AbstractProtocol<S> {
 
     private final CompressionConfig compressionConfig = new 
CompressionConfig();
 
+    private HttpParser httpParser = null;
 
     public AbstractHttp11Protocol(AbstractEndpoint<S,?> endpoint) {
         super(endpoint);
@@ -82,6 +84,8 @@ public abstract class AbstractHttp11Protocol<S> extends 
AbstractProtocol<S> {
         for (UpgradeProtocol upgradeProtocol : upgradeProtocols) {
             upgradeProtocol.setHttp11Protocol(this);
         }
+
+        httpParser = new HttpParser(relaxedPathChars, relaxedQueryChars);
     }
 
 
@@ -120,6 +124,11 @@ public abstract class AbstractHttp11Protocol<S> extends 
AbstractProtocol<S> {
     }
 
 
+    public HttpParser getHttpParser() {
+        return httpParser;
+    }
+
+
     // ------------------------------------------------ HTTP specific 
properties
     // ------------------------------------------ managed in the 
ProtocolHandler
 
diff --git a/java/org/apache/coyote/http11/Http11Processor.java 
b/java/org/apache/coyote/http11/Http11Processor.java
index fd7d94664c..50fc2b5dff 100644
--- a/java/org/apache/coyote/http11/Http11Processor.java
+++ b/java/org/apache/coyote/http11/Http11Processor.java
@@ -92,9 +92,6 @@ public class Http11Processor extends AbstractProcessor {
     private final Http11OutputBuffer outputBuffer;
 
 
-    private final HttpParser httpParser;
-
-
     /**
      * Tracks how many internal filters are in the filter library so they are 
skipped when looking for pluggable
      * filters.
@@ -154,10 +151,8 @@ public class Http11Processor extends AbstractProcessor {
         super(adapter);
         this.protocol = protocol;
 
-        httpParser = new HttpParser(protocol.getRelaxedPathChars(), 
protocol.getRelaxedQueryChars());
-
         inputBuffer = new Http11InputBuffer(request, 
protocol.getMaxHttpRequestHeaderSize(),
-                protocol.getRejectIllegalHeader(), httpParser);
+                protocol.getRejectIllegalHeader(), protocol.getHttpParser());
         request.setInputBuffer(inputBuffer);
 
         outputBuffer = new Http11OutputBuffer(response, 
protocol.getMaxHttpResponseHeaderSize());
@@ -769,7 +764,7 @@ public class Http11Processor extends AbstractProcessor {
         // Validate the characters in the URI. %nn decoding will be checked at
         // the point of decoding.
         for (int i = uriBC.getStart(); i < uriBC.getEnd(); i++) {
-            if (!httpParser.isAbsolutePathRelaxed(uriB[i])) {
+            if (!protocol.getHttpParser().isAbsolutePathRelaxed(uriB[i])) {
                 badRequest("http11processor.request.invalidUri");
                 break;
             }
diff --git a/java/org/apache/coyote/http2/StreamProcessor.java 
b/java/org/apache/coyote/http2/StreamProcessor.java
index b7d6e9e6ce..78a676e271 100644
--- a/java/org/apache/coyote/http2/StreamProcessor.java
+++ b/java/org/apache/coyote/http2/StreamProcessor.java
@@ -483,8 +483,7 @@ class StreamProcessor extends AbstractProcessor {
      * The checks performed below are based on the checks in Http11InputBuffer.
      */
     private boolean validateRequest() {
-        HttpParser httpParser = new 
HttpParser(handler.getProtocol().getHttp11Protocol().getRelaxedPathChars(),
-                
handler.getProtocol().getHttp11Protocol().getRelaxedQueryChars());
+        HttpParser httpParser = 
handler.getProtocol().getHttp11Protocol().getHttpParser();
 
         // Method name must be a token
         String method = request.method().toString();
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 3a6fa24740..fbb289e803 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -129,6 +129,11 @@
         Ensure that HTTP/2 stream input buffers are only created when there is 
a
         request body to be read. (markt)
       </fix>
+      <scode>
+        Refactor creation of HttpParser instances from the Processor level to
+        the Protocol level since the parser configuration depends on the
+        protocol and the parser is, otherwise, stateless. (markt)
+      </scode>
     </changelog>
   </subsection>
   <subsection name="jdbc-pool">


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

Reply via email to