(tomcat) branch 9.0.x updated: Handle maxSavePostSize=0 case for HTTP/1.1 to HTTP/2 upgrade with body
[email protected] Mon, 20 Jul 2026 13:29:45 +0000
| Newsgroups | gmane.comp.jakarta.tomcat.devel |
|---|---|
| Message-ID | <[email protected]> |
This is an automated email from the ASF dual-hosted git repository.
markt-asf pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/9.0.x by this push:
new 9d4cbd8264 Handle maxSavePostSize=0 case for HTTP/1.1 to HTTP/2 upgrade with body
9d4cbd8264 is described below
commit 9d4cbd826463bca4462a03c19dca35192f06343e
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 5f48603abd..0d606af7e4 100644
--- a/java/org/apache/catalina/authenticator/FormAuthenticator.java
+++ b/java/org/apache/catalina/authenticator/FormAuthenticator.java
@@ -701,6 +701,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 2c0d8f5b33..9172073405 100644
--- a/java/org/apache/coyote/http11/Http11Processor.java
+++ b/java/org/apache/coyote/http11/Http11Processor.java
@@ -350,6 +350,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);
@@ -358,7 +360,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 290e39e9e9..ff03f0def7 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">