Author: markt Date: Tue May 28 11:26:20 2013 New Revision: 1486875 URL: http://svn.apache.org/r1486875 Log: Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=54947 NIO connector incorrectly rejects a request if the CRLF terminating the request line is split across multiple packets. Patch for the fix by Konstantin Preißer. I added a test case.
Modified: tomcat/trunk/java/org/apache/coyote/http11/InternalNioInputBuffer.java tomcat/trunk/test/org/apache/catalina/startup/SimpleHttpClient.java tomcat/trunk/test/org/apache/coyote/http11/TestInternalInputBuffer.java Modified: tomcat/trunk/java/org/apache/coyote/http11/InternalNioInputBuffer.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/InternalNioInputBuffer.java?rev=1486875&r1=1486874&r2=1486875&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/coyote/http11/InternalNioInputBuffer.java (original) +++ tomcat/trunk/java/org/apache/coyote/http11/InternalNioInputBuffer.java Tue May 28 11:26:20 2013 @@ -372,11 +372,11 @@ public class InternalNioInputBuffer exte } parsingRequestLineStart = pos; parsingRequestLinePhase = 6; - } - if (parsingRequestLinePhase == 6) { - // Mark the current buffer position + // Mark the current buffer position end = 0; + } + if (parsingRequestLinePhase == 6) { // // Reading the protocol // Protocol is always US-ASCII Modified: tomcat/trunk/test/org/apache/catalina/startup/SimpleHttpClient.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/startup/SimpleHttpClient.java?rev=1486875&r1=1486874&r2=1486875&view=diff ============================================================================== --- tomcat/trunk/test/org/apache/catalina/startup/SimpleHttpClient.java (original) +++ tomcat/trunk/test/org/apache/catalina/startup/SimpleHttpClient.java Tue May 28 11:26:20 2013 @@ -42,7 +42,9 @@ public abstract class SimpleHttpClient { public static final String TEMP_DIR = System.getProperty("java.io.tmpdir"); - public static final String CRLF = "\r\n"; + public static final String CR = "\r"; + public static final String LF = "\n"; + public static final String CRLF = CR + LF; public static final String INFO_100 = "HTTP/1.1 100"; public static final String OK_200 = "HTTP/1.1 200"; Modified: tomcat/trunk/test/org/apache/coyote/http11/TestInternalInputBuffer.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/coyote/http11/TestInternalInputBuffer.java?rev=1486875&r1=1486874&r2=1486875&view=diff ============================================================================== --- tomcat/trunk/test/org/apache/coyote/http11/TestInternalInputBuffer.java (original) +++ tomcat/trunk/test/org/apache/coyote/http11/TestInternalInputBuffer.java Tue May 28 11:26:20 2013 @@ -415,4 +415,67 @@ public class TestInternalInputBuffer ext } + /** + * Test case for https://issues.apache.org/bugzilla/show_bug.cgi?id=54947 + */ + @Test + public void testBug54947() { + + Bug54947Client client = new Bug54947Client(); + + client.doRequest(); + assertTrue(client.isResponse200()); + assertTrue(client.isResponseBodyOK()); + } + + + /** + * Bug 54947 test client. + */ + private class Bug54947Client extends SimpleHttpClient { + + private Exception doRequest() { + + Tomcat tomcat = getTomcatInstance(); + + Context root = tomcat.addContext("", TEMP_DIR); + Tomcat.addServlet(root, "Bug54947", new TesterServlet()); + root.addServletMapping("/test", "Bug54947"); + + try { + tomcat.start(); + setPort(tomcat.getConnector().getLocalPort()); + + // Open connection + connect(); + + String[] request = new String[2]; + request[0] = "GET http://localhost:8080/test HTTP/1.1" + CR; + request[1] = LF + + "Connection: close" + CRLF + + CRLF; + + setRequest(request); + processRequest(); // blocks until response has been read + + // Close the connection + disconnect(); + } catch (Exception e) { + return e; + } + return null; + } + + @Override + public boolean isResponseBodyOK() { + if (getResponseBody() == null) { + return false; + } + if (!getResponseBody().contains("OK")) { + return false; + } + return true; + } + + } } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org