This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 9.0.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit e00735c3f672c19b6a0190be65f6e97f4747d04b 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 | 4 +--- webapps/docs/changelog.xml | 5 +++++ 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/java/org/apache/coyote/http11/AbstractHttp11Protocol.java b/java/org/apache/coyote/http11/AbstractHttp11Protocol.java index fa9455b685..13c4d43035 100644 --- a/java/org/apache/coyote/http11/AbstractHttp11Protocol.java +++ b/java/org/apache/coyote/http11/AbstractHttp11Protocol.java @@ -43,6 +43,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; @@ -56,6 +57,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); @@ -80,6 +82,8 @@ public abstract class AbstractHttp11Protocol<S> extends AbstractProtocol<S> { for (UpgradeProtocol upgradeProtocol : upgradeProtocols) { upgradeProtocol.setHttp11Protocol(this); } + + httpParser = new HttpParser(relaxedPathChars, relaxedQueryChars); } @@ -118,6 +122,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 a388e89007..3166903227 100644 --- a/java/org/apache/coyote/http11/Http11Processor.java +++ b/java/org/apache/coyote/http11/Http11Processor.java @@ -91,9 +91,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. @@ -153,10 +150,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()); @@ -768,7 +763,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 78b76ed86b..1f3253b1fa 100644 --- a/java/org/apache/coyote/http2/StreamProcessor.java +++ b/java/org/apache/coyote/http2/StreamProcessor.java @@ -483,9 +483,7 @@ class StreamProcessor extends AbstractProcessor { * The checks performed below are based on the checks in Http11InputBuffer. */ private boolean validateRequest() { - HttpParser httpParser = new HttpParser( - ((AbstractHttp11Protocol<?>) handler.getProtocol().getHttp11Protocol()).getRelaxedPathChars(), - ((AbstractHttp11Protocol<?>) handler.getProtocol().getHttp11Protocol()).getRelaxedQueryChars()); + HttpParser httpParser = ((AbstractHttp11Protocol<?>) 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 7e2e343212..0a983a0b1a 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -136,6 +136,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