This is an automated email from the ASF dual-hosted git repository.
markt-asf pushed a commit to branch 11.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/11.0.x by this push:
new fd8c5d7a63 Handle maxSavePostSize=0 case for HTTP/1.1 to HTTP/2
upgrade with body
fd8c5d7a63 is described below
commit fd8c5d7a631ece6f47be4b4f641151bf0dcd4ff7
Author: Mark Thomas <[email protected]>
AuthorDate: Mon Jul 20 14:29:18 2026 +0100
Handle maxSavePostSize=0 case for HTTP/1.1 to HTTP/2 upgrade with body
---
.../catalina/authenticator/FormAuthenticator.java | 1 +
java/org/apache/coyote/http11/Http11Processor.java | 4 +++-
.../coyote/http2/TestHttp2UpgradeHandler.java | 24 ++++++++++++++++++++++
webapps/docs/changelog.xml | 4 ++++
4 files changed, 32 insertions(+), 1 deletion(-)
diff --git a/java/org/apache/catalina/authenticator/FormAuthenticator.java
b/java/org/apache/catalina/authenticator/FormAuthenticator.java
index dde079f227..5480c1186c 100644
--- a/java/org/apache/catalina/authenticator/FormAuthenticator.java
+++ b/java/org/apache/catalina/authenticator/FormAuthenticator.java
@@ -696,6 +696,7 @@ public class FormAuthenticator extends AuthenticatorBase {
// May need to acknowledge a 100-continue expectation
request.getResponse().sendAcknowledgement(ContinueResponseTiming.ALWAYS);
+ // If maxSavePostSize == 0, the body will be swallowed when the
processor calls inputBuffer.endRequest()
int maxSavePostSize = request.getConnector().getMaxSavePostSize();
if (maxSavePostSize != 0) {
ByteChunk body = new ByteChunk();
diff --git a/java/org/apache/coyote/http11/Http11Processor.java
b/java/org/apache/coyote/http11/Http11Processor.java
index 1d2f810f26..a5a566e337 100644
--- a/java/org/apache/coyote/http11/Http11Processor.java
+++ b/java/org/apache/coyote/http11/Http11Processor.java
@@ -349,6 +349,8 @@ public class Http11Processor extends AbstractProcessor {
Request upgradeRequest = null;
try {
upgradeRequest = cloneRequest(request);
+ // Make sure any remaining body is swallowed
before we start processing the upgraded protocol
+ inputBuffer.endRequest();
} catch (ByteChunk.BufferOverflowException ioe) {
response.setStatus(HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE);
setErrorState(ErrorState.CLOSE_CLEAN, null);
@@ -357,7 +359,7 @@ public class Http11Processor extends AbstractProcessor {
setErrorState(ErrorState.CLOSE_CLEAN, ioe);
}
- if (upgradeRequest != null) {
+ if (upgradeRequest != null &&
!getErrorState().isError()) {
// Complete the HTTP/1.1 upgrade process
response.setStatus(HttpServletResponse.SC_SWITCHING_PROTOCOLS);
response.setHeader("Connection", "Upgrade");
diff --git a/test/org/apache/coyote/http2/TestHttp2UpgradeHandler.java
b/test/org/apache/coyote/http2/TestHttp2UpgradeHandler.java
index 12fecd6f90..c36ef53374 100644
--- a/test/org/apache/coyote/http2/TestHttp2UpgradeHandler.java
+++ b/test/org/apache/coyote/http2/TestHttp2UpgradeHandler.java
@@ -66,6 +66,30 @@ public class TestHttp2UpgradeHandler extends Http2TestBase {
}
+ @Test
+ public void testUpgradeWithRequestBodyNoSavePostSize() throws Exception {
+ enableHttp2();
+
+ Tomcat tomcat = getTomcatInstance();
+ tomcat.getConnector().setProperty("maxSavePostSize", "0");
+ configureAndStartWebApplication();
+
+ openClientConnection();
+
+ byte[] upgradeRequest =
+ ("GET /simple HTTP/1.1\r\n" + "Host: localhost:" + getPort() +
"\r\n" + "Content-Length: 18\r\n" +
+ "Connection: Upgrade,HTTP2-Settings\r\n" + "Upgrade:
h2c\r\n" + EMPTY_HTTP2_SETTINGS_HEADER +
+ "\r\n" + "Small request
body").getBytes(StandardCharsets.ISO_8859_1);
+ os.write(upgradeRequest);
+ os.flush();
+
+ Assert.assertTrue("Failed to read HTTP Upgrade response",
readHttpUpgradeResponse());
+
+ sendClientPreface();
+ validateHttp2InitialResponse();
+ }
+
+
@Test
public void testUpgradeWithRequestBodyGet() throws Exception {
doTestUpgradeWithRequestBody(false, false, false);
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 1eed129211..0846eaf124 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -156,6 +156,10 @@
Add utility AutoCloseable URLConnection wrapper, and use it to cleanup
existing code patterns. (remm/markt)
</update>
+ <fix>
+ When processing an HTTP upgrade from HTTP/1.1 to HTTP/2, ensure that
all
+ the HTTP/1.1 data has been processed before switching protocols.
(markt)
+ </fix>
</changelog>
</subsection>
<subsection name="Jasper">
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]