This is an automated email from the ASF dual-hosted git repository. markt 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 7eae54393e Http11Processor's keep alive state and input buffer's swallow state must be synchronized (#550) 7eae54393e is described below commit 7eae54393e6bac1771a719219714c860e216184c Author: Malay Shah <malays...@gmail.com> AuthorDate: Mon Sep 12 08:42:03 2022 -0700 Http11Processor's keep alive state and input buffer's swallow state must be synchronized (#550) * Fixing a bug where a connection would be kept alive without swallowing the input from the request stream. When a request comes in with a 100 Continue expectation, and the server immediately responds with a 200 status without reading the request body at all, the next request on the connection will fail because Tomcat cannot parse the HTTP verb. The new unit test replicates the issue and is addressed by removing the unnecessary changes to the swallowInput field of the Http11InputBuffer. --- java/org/apache/coyote/http11/Http11Processor.java | 2 - .../apache/coyote/http11/TestHttp11Processor.java | 51 ++++++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/java/org/apache/coyote/http11/Http11Processor.java b/java/org/apache/coyote/http11/Http11Processor.java index 0094ade7aa..fdc4cc395c 100644 --- a/java/org/apache/coyote/http11/Http11Processor.java +++ b/java/org/apache/coyote/http11/Http11Processor.java @@ -803,7 +803,6 @@ public class Http11Processor extends AbstractProcessor { MessageBytes expectMB = headers.getValue("expect"); if (expectMB != null && !expectMB.isNull()) { if (expectMB.toString().trim().equalsIgnoreCase("100-continue")) { - inputBuffer.setSwallowInput(false); request.setExpectation(true); } else { response.setStatus(HttpServletResponse.SC_EXPECTATION_FAILED); @@ -1253,7 +1252,6 @@ public class Http11Processor extends AbstractProcessor { // Send a 100 status back if it makes sense (response not committed // yet, and client specified an expectation for 100-continue) if (!response.isCommitted() && request.hasExpectation()) { - inputBuffer.setSwallowInput(true); try { outputBuffer.sendAck(); } catch (IOException e) { diff --git a/test/org/apache/coyote/http11/TestHttp11Processor.java b/test/org/apache/coyote/http11/TestHttp11Processor.java index dbc3ba8d00..d2c677d566 100644 --- a/test/org/apache/coyote/http11/TestHttp11Processor.java +++ b/test/org/apache/coyote/http11/TestHttp11Processor.java @@ -1953,4 +1953,55 @@ public class TestHttp11Processor extends TomcatBaseTest { Assert.assertTrue(client.isResponse200()); Assert.assertTrue(client.getResponseBody().contains("test - data")); } + + + @Test + public void test100ContinueWithNoAck() throws Exception { + Tomcat tomcat = getTomcatInstance(); + + final Connector connector = tomcat.getConnector(); + connector.setProperty("continueResponseTiming", "onRead"); + + // No file system docBase required + Context ctx = tomcat.addContext("", null); + + // Add servlet + Tomcat.addServlet(ctx, "TestPostNoReadServlet", new TestPostNoReadServlet()); + ctx.addServletMappingDecoded("/foo", "TestPostNoReadServlet"); + + tomcat.start(); + + String request = + "POST /foo HTTP/1.1" + SimpleHttpClient.CRLF + + "Host: localhost:" + getPort() + SimpleHttpClient.CRLF + + "Expect: 100-continue" + SimpleHttpClient.CRLF + + "Content-Length: 10" + SimpleHttpClient.CRLF + + SimpleHttpClient.CRLF + + "0123456789"; + + Client client = new Client(tomcat.getConnector().getLocalPort()); + client.setRequest(new String[] {request}); + + client.connect(); + client.processRequest(false); + + Assert.assertTrue(client.isResponse200()); + + if (client.getResponseHeaders().contains("Connection: close")) { + client.connect(); + } + + client.processRequest(false); + + Assert.assertTrue(client.isResponse200()); + + } + + + private static class TestPostNoReadServlet extends HttpServlet { + @Override + protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + + } + } } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org