This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 7.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit 47c9f3813795f881f1d9b93ec3c1a259641f1a06
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Wed Jan 15 19:40:52 2020 +0000

    Use setProperty and test return value in preference to setAttribute
---
 .../apache/catalina/core/ApplicationContext.java   |   2 +-
 .../connector/TestCoyoteAdapterRequestFuzzing.java |   2 +-
 .../apache/catalina/core/TestAsyncContextImpl.java |   3 +-
 .../catalina/core/TestSwallowAbortedUploads.java   |   2 +-
 .../apache/catalina/mbeans/TestRegistration.java   |   2 +-
 .../apache/catalina/startup/TomcatBaseTest.java    |   7 +-
 .../coyote/http11/TestAbstractHttp11Processor.java | 650 +++++++++++++++++++++
 .../apache/tomcat/util/http/TestMimeHeaders.java   |   3 +-
 test/org/apache/tomcat/util/net/TestCustomSsl.java |   7 +-
 test/org/apache/tomcat/util/net/TesterSupport.java |  22 +-
 10 files changed, 673 insertions(+), 27 deletions(-)

diff --git a/java/org/apache/catalina/core/ApplicationContext.java 
b/java/org/apache/catalina/core/ApplicationContext.java
index 833c06e..dfd02a9 100644
--- a/java/org/apache/catalina/core/ApplicationContext.java
+++ b/java/org/apache/catalina/core/ApplicationContext.java
@@ -1043,7 +1043,7 @@ public class ApplicationContext implements ServletContext 
{
         Connector[] connectors = service.findConnectors();
         // Need at least one SSL enabled connector to use the SSL session ID.
         for (Connector connector : connectors) {
-            if (Boolean.TRUE.equals(connector.getAttribute("SSLEnabled"))) {
+            if (Boolean.TRUE.equals(connector.getProperty("SSLEnabled"))) {
                 supportedSessionTrackingModes.add(SessionTrackingMode.SSL);
                 break;
             }
diff --git 
a/test/org/apache/catalina/connector/TestCoyoteAdapterRequestFuzzing.java 
b/test/org/apache/catalina/connector/TestCoyoteAdapterRequestFuzzing.java
index b998ba1..6c89fd3 100644
--- a/test/org/apache/catalina/connector/TestCoyoteAdapterRequestFuzzing.java
+++ b/test/org/apache/catalina/connector/TestCoyoteAdapterRequestFuzzing.java
@@ -110,7 +110,7 @@ public class TestCoyoteAdapterRequestFuzzing extends 
TomcatBaseTest {
     @Test
     public void doTest() throws Exception {
         Tomcat tomcat = getTomcatInstance();
-        tomcat.getConnector().setAttribute("restrictedUserAgents", 
"value-not-important");
+        
Assert.assertTrue(tomcat.getConnector().setProperty("restrictedUserAgents", 
"value-not-important"));
 
         File appDir = new File("test/webapp");
         Context ctxt = tomcat.addContext("", appDir.getAbsolutePath());
diff --git a/test/org/apache/catalina/core/TestAsyncContextImpl.java 
b/test/org/apache/catalina/core/TestAsyncContextImpl.java
index 7aff34b..54a9e8b 100644
--- a/test/org/apache/catalina/core/TestAsyncContextImpl.java
+++ b/test/org/apache/catalina/core/TestAsyncContextImpl.java
@@ -165,8 +165,7 @@ public class TestAsyncContextImpl extends TomcatBaseTest {
         Tomcat tomcat = getTomcatInstance();
 
         // Minimise pauses during test
-        tomcat.getConnector().setAttribute(
-                "connectionTimeout", Integer.valueOf(3000));
+        
Assert.assertTrue(tomcat.getConnector().setProperty("connectionTimeout", 
"3000"));
 
         // No file system docBase required
         Context ctx = tomcat.addContext("", null);
diff --git a/test/org/apache/catalina/core/TestSwallowAbortedUploads.java 
b/test/org/apache/catalina/core/TestSwallowAbortedUploads.java
index b8f71ed..450d9fc 100644
--- a/test/org/apache/catalina/core/TestSwallowAbortedUploads.java
+++ b/test/org/apache/catalina/core/TestSwallowAbortedUploads.java
@@ -430,7 +430,7 @@ public class TestSwallowAbortedUploads extends 
TomcatBaseTest {
         // No need for target to exist.
 
         if (!limit) {
-            tomcat.getConnector().setAttribute("maxSwallowSize", "-1");
+            
Assert.assertTrue(tomcat.getConnector().setProperty("maxSwallowSize", "-1"));
         }
 
         tomcat.start();
diff --git a/test/org/apache/catalina/mbeans/TestRegistration.java 
b/test/org/apache/catalina/mbeans/TestRegistration.java
index 892ff8d..bc14553 100644
--- a/test/org/apache/catalina/mbeans/TestRegistration.java
+++ b/test/org/apache/catalina/mbeans/TestRegistration.java
@@ -169,7 +169,7 @@ public class TestRegistration extends TomcatBaseTest {
         // Disable keep-alive otherwise request processing threads in 
keep-alive
         // won't shut down fast enough with BIO to de-register the processor
         // triggering a test failure
-        tomcat.getConnector().setAttribute("maxKeepAliveRequests", 
Integer.valueOf(1));
+        
Assert.assertTrue(tomcat.getConnector().setProperty("maxKeepAliveRequests", 
"1"));
 
         tomcat.start();
 
diff --git a/test/org/apache/catalina/startup/TomcatBaseTest.java 
b/test/org/apache/catalina/startup/TomcatBaseTest.java
index eec6416..e0757d8 100644
--- a/test/org/apache/catalina/startup/TomcatBaseTest.java
+++ b/test/org/apache/catalina/startup/TomcatBaseTest.java
@@ -112,12 +112,11 @@ public abstract class TomcatBaseTest extends 
LoggingBaseTest {
         String protocol = getProtocol();
         Connector connector = new Connector(protocol);
         // Listen only on localhost
-        connector.setAttribute("address",
-                InetAddress.getByName("localhost").getHostAddress());
+        Assert.assertTrue(connector.setProperty("address", 
InetAddress.getByName("localhost").getHostAddress()));
         // Use random free port
         connector.setPort(0);
         // Mainly set to reduce timeouts during async tests
-        connector.setAttribute("connectionTimeout", "3000");
+        Assert.assertTrue(connector.setProperty("connectionTimeout", "3000"));
         tomcat.getService().addConnector(connector);
         tomcat.setConnector(connector);
 
@@ -127,7 +126,7 @@ public abstract class TomcatBaseTest extends 
LoggingBaseTest {
             AprLifecycleListener listener = new AprLifecycleListener();
             listener.setSSLRandomSeed("/dev/urandom");
             server.addLifecycleListener(listener);
-            connector.setAttribute("pollerThreadCount", Integer.valueOf(1));
+            Assert.assertTrue(connector.setProperty("pollerThreadCount", "1"));
         }
 
         File catalinaBase = getTemporaryDirectory();
diff --git a/test/org/apache/coyote/http11/TestAbstractHttp11Processor.java 
b/test/org/apache/coyote/http11/TestAbstractHttp11Processor.java
index 6f71fab..b142431 100644
--- a/test/org/apache/coyote/http11/TestAbstractHttp11Processor.java
+++ b/test/org/apache/coyote/http11/TestAbstractHttp11Processor.java
@@ -25,11 +25,13 @@ import java.io.OutputStream;
 import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
 import java.io.Reader;
+import java.io.StringReader;
 import java.io.Writer;
 import java.net.InetSocketAddress;
 import java.net.Socket;
 import java.net.SocketAddress;
 import java.nio.CharBuffer;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -56,6 +58,7 @@ import org.apache.catalina.startup.Tomcat;
 import org.apache.catalina.startup.TomcatBaseTest;
 import org.apache.tomcat.util.buf.B2CConverter;
 import org.apache.tomcat.util.buf.ByteChunk;
+import org.apache.tomcat.util.http.parser.TokenList;
 
 public class TestAbstractHttp11Processor extends TomcatBaseTest {
 
@@ -63,6 +66,10 @@ public class TestAbstractHttp11Processor extends 
TomcatBaseTest {
     public void testResponseWithErrorChunked() throws Exception {
         Tomcat tomcat = getTomcatInstance();
 
+        // This setting means the connection will be closed at the end of the
+        // request
+        
Assert.assertTrue(tomcat.getConnector().setProperty("maxKeepAliveRequests", 
"1"));
+
         // No file system docBase required
         Context ctxt = tomcat.addContext("", null);
 
@@ -1079,4 +1086,647 @@ public class TestAbstractHttp11Processor extends 
TomcatBaseTest {
             resp.setStatus(205);
         }
     }
+
+    /*
+     * Multiple, different Host headers
+     */
+    @Test
+    public void testMultipleHostHeader01() throws Exception {
+        Tomcat tomcat = getTomcatInstance();
+
+        // This setting means the connection will be closed at the end of the
+        // request
+        
Assert.assertTrue(tomcat.getConnector().setProperty("maxKeepAliveRequests", 
"1"));
+
+        // No file system docBase required
+        Context ctx = tomcat.addContext("", null);
+
+        // Add servlet
+        Tomcat.addServlet(ctx, "TesterServlet", new TesterServlet());
+        ctx.addServletMapping("/foo", "TesterServlet");
+
+        tomcat.start();
+
+        String request =
+                "GET /foo HTTP/1.1" + SimpleHttpClient.CRLF +
+                "Host: a" + SimpleHttpClient.CRLF +
+                "Host: b" + SimpleHttpClient.CRLF +
+                 SimpleHttpClient.CRLF;
+
+        Client client = new Client(tomcat.getConnector().getLocalPort());
+        client.setRequest(new String[] {request});
+
+        client.connect();
+        client.processRequest();
+
+        // Expected response is a 400 response.
+        Assert.assertTrue(client.isResponse400());
+    }
+
+    /*
+     * Multiple instances of the same Host header
+     */
+    @Test
+    public void testMultipleHostHeader02() throws Exception {
+        Tomcat tomcat = getTomcatInstance();
+
+        // This setting means the connection will be closed at the end of the
+        // request
+        
Assert.assertTrue(tomcat.getConnector().setProperty("maxKeepAliveRequests", 
"1"));
+
+        // No file system docBase required
+        Context ctx = tomcat.addContext("", null);
+
+        // Add servlet
+        Tomcat.addServlet(ctx, "TesterServlet", new TesterServlet());
+        ctx.addServletMapping("/foo", "TesterServlet");
+
+        tomcat.start();
+
+        String request =
+                "GET /foo HTTP/1.1" + SimpleHttpClient.CRLF +
+                "Host: a" + SimpleHttpClient.CRLF +
+                "Host: a" + SimpleHttpClient.CRLF +
+                 SimpleHttpClient.CRLF;
+
+        Client client = new Client(tomcat.getConnector().getLocalPort());
+        client.setRequest(new String[] {request});
+
+        client.connect();
+        client.processRequest();
+
+        // Expected response is a 400 response.
+        Assert.assertTrue(client.isResponse400());
+    }
+
+    @Test
+    public void testMissingHostHeader() throws Exception {
+        Tomcat tomcat = getTomcatInstance();
+
+        // This setting means the connection will be closed at the end of the
+        // request
+        
Assert.assertTrue(tomcat.getConnector().setProperty("maxKeepAliveRequests", 
"1"));
+
+        // No file system docBase required
+        Context ctx = tomcat.addContext("", null);
+
+        // Add servlet
+        Tomcat.addServlet(ctx, "TesterServlet", new TesterServlet());
+        ctx.addServletMapping("/foo", "TesterServlet");
+
+        tomcat.start();
+
+        String request =
+                "GET /foo HTTP/1.1" + SimpleHttpClient.CRLF +
+                 SimpleHttpClient.CRLF;
+
+        Client client = new Client(tomcat.getConnector().getLocalPort());
+        client.setRequest(new String[] {request});
+
+        client.connect();
+        client.processRequest();
+
+        // Expected response is a 400 response.
+        Assert.assertTrue(client.isResponse400());
+    }
+
+    @Test
+    public void testInconsistentHostHeader01() throws Exception {
+        Tomcat tomcat = getTomcatInstance();
+
+        // This setting means the connection will be closed at the end of the
+        // request
+        
Assert.assertTrue(tomcat.getConnector().setProperty("maxKeepAliveRequests", 
"1"));
+
+        
Assert.assertTrue(tomcat.getConnector().setProperty("allowHostHeaderMismatch", 
"false"));
+
+        // No file system docBase required
+        Context ctx = tomcat.addContext("", null);
+
+        // Add servlet
+        Tomcat.addServlet(ctx, "TesterServlet", new TesterServlet());
+        ctx.addServletMapping("/foo", "TesterServlet");
+
+        tomcat.start();
+
+        String request =
+                "GET http://a/foo HTTP/1.1" + SimpleHttpClient.CRLF +
+                "Host: b" + SimpleHttpClient.CRLF +
+                 SimpleHttpClient.CRLF;
+
+        Client client = new Client(tomcat.getConnector().getLocalPort());
+        client.setRequest(new String[] {request});
+
+        client.connect();
+        client.processRequest();
+
+        // Expected response is a 400 response.
+        Assert.assertTrue(client.isResponse400());
+    }
+
+    @Test
+    public void testInconsistentHostHeader02() throws Exception {
+        Tomcat tomcat = getTomcatInstance();
+
+        // This setting means the connection will be closed at the end of the
+        // request
+        
Assert.assertTrue(tomcat.getConnector().setProperty("maxKeepAliveRequests", 
"1"));
+
+        
Assert.assertTrue(tomcat.getConnector().setProperty("allowHostHeaderMismatch", 
"false"));
+
+        // No file system docBase required
+        Context ctx = tomcat.addContext("", null);
+
+        // Add servlet
+        Tomcat.addServlet(ctx, "TesterServlet", new TesterServlet());
+        ctx.addServletMapping("/foo", "TesterServlet");
+
+        tomcat.start();
+
+        String request =
+                "GET http://a:8080/foo HTTP/1.1" + SimpleHttpClient.CRLF +
+                "Host: b:8080" + SimpleHttpClient.CRLF +
+                 SimpleHttpClient.CRLF;
+
+        Client client = new Client(tomcat.getConnector().getLocalPort());
+        client.setRequest(new String[] {request});
+
+        client.connect();
+        client.processRequest();
+
+        // Expected response is a 400 response.
+        Assert.assertTrue(client.isResponse400());
+    }
+
+    @Test
+    public void testInconsistentHostHeader03() throws Exception {
+        Tomcat tomcat = getTomcatInstance();
+
+        // This setting means the connection will be closed at the end of the
+        // request
+        
Assert.assertTrue(tomcat.getConnector().setProperty("maxKeepAliveRequests", 
"1"));
+
+        
Assert.assertTrue(tomcat.getConnector().setProperty("allowHostHeaderMismatch", 
"false"));
+
+        // No file system docBase required
+        Context ctx = tomcat.addContext("", null);
+
+        // Add servlet
+        Tomcat.addServlet(ctx, "TesterServlet", new TesterServlet());
+        ctx.addServletMapping("/foo", "TesterServlet");
+
+        tomcat.start();
+
+        String request =
+                "GET http://user:pwd@a/foo HTTP/1.1" + SimpleHttpClient.CRLF +
+                "Host: b" + SimpleHttpClient.CRLF +
+                 SimpleHttpClient.CRLF;
+
+        Client client = new Client(tomcat.getConnector().getLocalPort());
+        client.setRequest(new String[] {request});
+
+        client.connect();
+        client.processRequest();
+
+        // Expected response is a 400 response.
+        Assert.assertTrue(client.isResponse400());
+    }
+
+    /*
+     * Hostname (no port) is included in the request line, but Host header
+     * is empty.
+     * Added for bug 62739.
+     */
+    @Test
+    public void testInconsistentHostHeader04() throws Exception {
+        Tomcat tomcat = getTomcatInstance();
+
+        // This setting means the connection will be closed at the end of the
+        // request
+        
Assert.assertTrue(tomcat.getConnector().setProperty("maxKeepAliveRequests", 
"1"));
+
+        
Assert.assertTrue(tomcat.getConnector().setProperty("allowHostHeaderMismatch", 
"false"));
+
+        // No file system docBase required
+        Context ctx = tomcat.addContext("", null);
+
+        // Add servlet
+        Tomcat.addServlet(ctx, "TesterServlet", new TesterServlet());
+        ctx.addServletMapping("/foo", "TesterServlet");
+
+        tomcat.start();
+
+        String request =
+                "GET http://a/foo HTTP/1.1" + SimpleHttpClient.CRLF +
+                "Host: " + SimpleHttpClient.CRLF +
+                 SimpleHttpClient.CRLF;
+
+        Client client = new Client(tomcat.getConnector().getLocalPort());
+        client.setRequest(new String[] {request});
+
+        client.connect();
+        client.processRequest();
+
+        // Expected response is a 400 response.
+        Assert.assertTrue(client.isResponse400());
+    }
+
+    /*
+     * Hostname (with port) is included in the request line, but Host header
+     * is empty.
+     * Added for bug 62739.
+     */
+    @Test
+    public void testInconsistentHostHeader05() throws Exception {
+        Tomcat tomcat = getTomcatInstance();
+
+        // This setting means the connection will be closed at the end of the
+        // request
+        
Assert.assertTrue(tomcat.getConnector().setProperty("maxKeepAliveRequests", 
"1"));
+
+        
Assert.assertTrue(tomcat.getConnector().setProperty("allowHostHeaderMismatch", 
"false"));
+
+        // No file system docBase required
+        Context ctx = tomcat.addContext("", null);
+
+        // Add servlet
+        Tomcat.addServlet(ctx, "TesterServlet", new TesterServlet());
+        ctx.addServletMapping("/foo", "TesterServlet");
+
+        tomcat.start();
+
+        String request =
+                "GET http://a:8080/foo HTTP/1.1" + SimpleHttpClient.CRLF +
+                "Host: " + SimpleHttpClient.CRLF +
+                 SimpleHttpClient.CRLF;
+
+        Client client = new Client(tomcat.getConnector().getLocalPort());
+        client.setRequest(new String[] {request});
+
+        client.connect();
+        client.processRequest();
+
+        // Expected response is a 400 response.
+        Assert.assertTrue(client.isResponse400());
+    }
+
+    /*
+     * Hostname (with port and user) is included in the request line, but Host
+     * header is empty.
+     * Added for bug 62739.
+     */
+    @Test
+    public void testInconsistentHostHeader06() throws Exception {
+        Tomcat tomcat = getTomcatInstance();
+
+        // This setting means the connection will be closed at the end of the
+        // request
+        
Assert.assertTrue(tomcat.getConnector().setProperty("maxKeepAliveRequests", 
"1"));
+
+        
Assert.assertTrue(tomcat.getConnector().setProperty("allowHostHeaderMismatch", 
"false"));
+
+        // No file system docBase required
+        Context ctx = tomcat.addContext("", null);
+
+        // Add servlet
+        Tomcat.addServlet(ctx, "TesterServlet", new TesterServlet());
+        ctx.addServletMapping("/foo", "TesterServlet");
+
+        tomcat.start();
+
+        String request =
+                "GET http://user:pwd@a/foo HTTP/1.1" + SimpleHttpClient.CRLF +
+                "Host: " + SimpleHttpClient.CRLF +
+                 SimpleHttpClient.CRLF;
+
+        Client client = new Client(tomcat.getConnector().getLocalPort());
+        client.setRequest(new String[] {request});
+
+        client.connect();
+        client.processRequest();
+
+        // Expected response is a 400 response.
+        Assert.assertTrue(client.isResponse400());
+    }
+
+
+    /*
+     * Request line host is an exact match for Host header (no port)
+     */
+    @Test
+    public void testConsistentHostHeader01() throws Exception {
+        Tomcat tomcat = getTomcatInstance();
+
+        // This setting means the connection will be closed at the end of the
+        // request
+        
Assert.assertTrue(tomcat.getConnector().setProperty("maxKeepAliveRequests", 
"1"));
+
+        // No file system docBase required
+        Context ctx = tomcat.addContext("", null);
+
+        // Add servlet
+        Tomcat.addServlet(ctx, "TesterServlet", new ServerNameTesterServlet());
+        ctx.addServletMapping("/foo", "TesterServlet");
+
+        tomcat.start();
+
+        String request =
+                "GET http://a/foo HTTP/1.1" + SimpleHttpClient.CRLF +
+                "Host: a" + SimpleHttpClient.CRLF +
+                 SimpleHttpClient.CRLF;
+
+        Client client = new Client(tomcat.getConnector().getLocalPort());
+        client.setRequest(new String[] {request});
+
+        client.connect();
+        client.processRequest();
+
+        // Expected response is a 200 response.
+        Assert.assertTrue(client.isResponse200());
+        Assert.assertEquals("request.getServerName() is [a] and 
request.getServerPort() is 80", client.getResponseBody());
+    }
+
+    /*
+     * Request line host is an exact match for Host header (with port)
+     */
+    @Test
+    public void testConsistentHostHeader02() throws Exception {
+        Tomcat tomcat = getTomcatInstance();
+
+        // This setting means the connection will be closed at the end of the
+        // request
+        
Assert.assertTrue(tomcat.getConnector().setProperty("maxKeepAliveRequests", 
"1"));
+
+        // No file system docBase required
+        Context ctx = tomcat.addContext("", null);
+
+        // Add servlet
+        Tomcat.addServlet(ctx, "TesterServlet", new ServerNameTesterServlet());
+        ctx.addServletMapping("/foo", "TesterServlet");
+
+        tomcat.start();
+
+        String request =
+                "GET http://a:8080/foo HTTP/1.1" + SimpleHttpClient.CRLF +
+                "Host: a:8080" + SimpleHttpClient.CRLF +
+                 SimpleHttpClient.CRLF;
+
+        Client client = new Client(tomcat.getConnector().getLocalPort());
+        client.setRequest(new String[] {request});
+
+        client.connect();
+        client.processRequest();
+
+        // Expected response is a 200 response.
+        Assert.assertTrue(client.isResponse200());
+        Assert.assertEquals("request.getServerName() is [a] and 
request.getServerPort() is 8080", client.getResponseBody());
+
+    }
+
+    /*
+     * Request line host is an exact match for Host header
+     * (no port, with user info)
+     */
+    @Test
+    public void testConsistentHostHeader03() throws Exception {
+        Tomcat tomcat = getTomcatInstance();
+
+        // This setting means the connection will be closed at the end of the
+        // request
+        
Assert.assertTrue(tomcat.getConnector().setProperty("maxKeepAliveRequests", 
"1"));
+
+        // No file system docBase required
+        Context ctx = tomcat.addContext("", null);
+
+        // Add servlet
+        Tomcat.addServlet(ctx, "TesterServlet", new ServerNameTesterServlet());
+        ctx.addServletMapping("/foo", "TesterServlet");
+
+        tomcat.start();
+
+        String request =
+                "GET http://user:pwd@a/foo HTTP/1.1" + SimpleHttpClient.CRLF +
+                "Host: a" + SimpleHttpClient.CRLF +
+                 SimpleHttpClient.CRLF;
+
+        Client client = new Client(tomcat.getConnector().getLocalPort());
+        client.setRequest(new String[] {request});
+
+        client.connect();
+        client.processRequest();
+
+        // Expected response is a 200 response.
+        Assert.assertTrue(client.isResponse200());
+        Assert.assertEquals("request.getServerName() is [a] and 
request.getServerPort() is 80", client.getResponseBody());
+    }
+
+    /*
+     * Host header exists but its value is an empty string.  This is valid if
+     * the request line does not include a hostname/port.
+     * Added for bug 62739.
+     */
+    @Test
+    public void testBlankHostHeader01() throws Exception {
+        Tomcat tomcat = getTomcatInstance();
+
+        // This setting means the connection will be closed at the end of the
+        // request
+        
Assert.assertTrue(tomcat.getConnector().setProperty("maxKeepAliveRequests", 
"1"));
+
+        // No file system docBase required
+        Context ctx = tomcat.addContext("", null);
+
+        // Add servlet
+        Tomcat.addServlet(ctx, "TesterServlet", new ServerNameTesterServlet());
+        ctx.addServletMapping("/foo", "TesterServlet");
+
+        tomcat.start();
+
+        String request =
+                "GET /foo HTTP/1.1" + SimpleHttpClient.CRLF +
+                "Host: " + SimpleHttpClient.CRLF +
+                 SimpleHttpClient.CRLF;
+
+        Client client = new Client(tomcat.getConnector().getLocalPort());
+        client.setRequest(new String[] {request});
+
+        client.connect();
+        client.processRequest();
+
+        // Expected response is a 200 response.
+        Assert.assertTrue(client.isResponse200());
+        Assert.assertEquals("request.getServerName() is [] and 
request.getServerPort() is " + getPort(), client.getResponseBody());
+    }
+
+    /*
+     * Host header exists but has its value is empty (and there are multiple
+     * spaces after the ':'.  This is valid if the request line does not
+     * include a hostname/port.
+     * Added for bug 62739.
+     */
+    @Test
+    public void testBlankHostHeader02() throws Exception {
+        Tomcat tomcat = getTomcatInstance();
+
+        // This setting means the connection will be closed at the end of the
+        // request
+        
Assert.assertTrue(tomcat.getConnector().setProperty("maxKeepAliveRequests", 
"1"));
+
+        // No file system docBase required
+        Context ctx = tomcat.addContext("", null);
+
+        // Add servlet
+        Tomcat.addServlet(ctx, "TesterServlet", new ServerNameTesterServlet());
+        ctx.addServletMapping("/foo", "TesterServlet");
+
+        tomcat.start();
+
+        String request =
+                "GET /foo HTTP/1.1" + SimpleHttpClient.CRLF +
+                "Host:      " + SimpleHttpClient.CRLF +
+                 SimpleHttpClient.CRLF;
+
+        Client client = new Client(tomcat.getConnector().getLocalPort());
+        client.setRequest(new String[] {request});
+
+        client.connect();
+        client.processRequest();
+
+        // Expected response is a 200 response.
+        Assert.assertTrue(client.isResponse200());
+        Assert.assertEquals("request.getServerName() is [] and 
request.getServerPort() is " + getPort(), client.getResponseBody());
+    }
+
+
+    @Test
+    public void testKeepAliveHeader01() throws Exception {
+        doTestKeepAliveHeader(false, 3000, 10);
+    }
+
+    @Test
+    public void testKeepAliveHeader02() throws Exception {
+        doTestKeepAliveHeader(true, 5000, 1);
+    }
+
+    @Test
+    public void testKeepAliveHeader03() throws Exception {
+        doTestKeepAliveHeader(true, 5000, 10);
+    }
+
+    @Test
+    public void testKeepAliveHeader04() throws Exception {
+        doTestKeepAliveHeader(true, -1, 10);
+    }
+
+    @Test
+    public void testKeepAliveHeader05() throws Exception {
+        doTestKeepAliveHeader(true, -1, 1);
+    }
+
+    @Test
+    public void testKeepAliveHeader06() throws Exception {
+        doTestKeepAliveHeader(true, -1, -1);
+    }
+
+    private void doTestKeepAliveHeader(boolean sendKeepAlive, int 
keepAliveTimeout,
+            int maxKeepAliveRequests) throws Exception {
+        Tomcat tomcat = getTomcatInstance();
+
+        tomcat.getConnector().setProperty("keepAliveTimeout", 
Integer.toString(keepAliveTimeout));
+        tomcat.getConnector().setProperty("maxKeepAliveRequests", 
Integer.toString(maxKeepAliveRequests));
+
+        // No file system docBase required
+        Context ctx = tomcat.addContext("", null);
+
+        // Add servlet
+        Tomcat.addServlet(ctx, "TesterServlet", new TesterServlet());
+        ctx.addServletMapping("/foo", "TesterServlet");
+
+        tomcat.start();
+
+        String request =
+                "GET /foo HTTP/1.1" + SimpleHttpClient.CRLF +
+                "Host: localhost:" + getPort() + SimpleHttpClient.CRLF;
+
+        if (sendKeepAlive) {
+            request += "Connection: keep-alive" + SimpleHttpClient.CRLF;
+        }
+
+        request += SimpleHttpClient.CRLF;
+
+        Client client = new Client(tomcat.getConnector().getLocalPort());
+        client.setRequest(new String[] {request});
+
+        client.connect();
+        client.processRequest(false);
+
+        Assert.assertTrue(client.isResponse200());
+
+        String connectionHeaderValue = null;
+        String keepAliveHeaderValue = null;
+        for (String header : client.getResponseHeaders()) {
+            if (header.startsWith("Connection:")) {
+                connectionHeaderValue = header.substring(header.indexOf(':') + 
1).trim();
+            }
+            if (header.startsWith("Keep-Alive:")) {
+                keepAliveHeaderValue = header.substring(header.indexOf(':') + 
1).trim();
+            }
+        }
+
+        if (!sendKeepAlive || keepAliveTimeout < 0
+            && (maxKeepAliveRequests < 0 || maxKeepAliveRequests > 1)) {
+            Assert.assertNull(connectionHeaderValue);
+            Assert.assertNull(keepAliveHeaderValue);
+        } else {
+            List<String> connectionHeaders = new ArrayList<String>();
+            TokenList.parseTokenList(new StringReader(connectionHeaderValue), 
connectionHeaders);
+
+            if (sendKeepAlive && keepAliveTimeout > 0 &&
+                (maxKeepAliveRequests < 0 || maxKeepAliveRequests > 1)) {
+                Assert.assertEquals(1, connectionHeaders.size());
+                Assert.assertEquals("keep-alive", connectionHeaders.get(0));
+                Assert.assertEquals("timeout=" + keepAliveTimeout / 1000L, 
keepAliveHeaderValue);
+            }
+
+            if (sendKeepAlive && maxKeepAliveRequests == 1) {
+                Assert.assertEquals(1, connectionHeaders.size());
+                Assert.assertEquals("close", connectionHeaders.get(0));
+                Assert.assertNull(keepAliveHeaderValue);
+            }
+        }
+    }
+
+
+    /**
+     * Test servlet that prints out the values of
+     * HttpServletRequest.getServerName() and
+     * HttpServletRequest.getServerPort() in the response body, e.g.:
+     *
+     * "request.getServerName() is [foo] and request.getServerPort() is 8080"
+     *
+     * or:
+     *
+     * "request.getServerName() is null and request.getServerPort() is 8080"
+     */
+    private static class ServerNameTesterServlet extends HttpServlet {
+
+        private static final long serialVersionUID = 1L;
+
+        @Override
+        protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+                throws ServletException, IOException {
+
+            resp.setContentType("text/plain");
+            PrintWriter out = resp.getWriter();
+
+            if (null == req.getServerName())
+            {
+                out.print("request.getServerName() is null");
+            } else {
+                out.print("request.getServerName() is [" + req.getServerName() 
+ "]");
+            }
+
+            out.print(" and request.getServerPort() is " + 
req.getServerPort());
+        }
+    }
 }
diff --git a/test/org/apache/tomcat/util/http/TestMimeHeaders.java 
b/test/org/apache/tomcat/util/http/TestMimeHeaders.java
index 90faeb2..1d88468 100644
--- a/test/org/apache/tomcat/util/http/TestMimeHeaders.java
+++ b/test/org/apache/tomcat/util/http/TestMimeHeaders.java
@@ -104,8 +104,7 @@ public class TestMimeHeaders extends TomcatBaseTest {
         if (maxHeaderCount > 0) {
             Assert.assertEquals(maxHeaderCount, alv.arraySize);
         } else if (maxHeaderCount < 0) {
-            int maxHttpHeaderSize = ((Integer) tomcat.getConnector()
-                    .getAttribute("maxHttpHeaderSize")).intValue();
+            int maxHttpHeaderSize = ((Integer) 
tomcat.getConnector().getProperty("maxHttpHeaderSize")).intValue();
             int headerCount = Math.min(count,
                     maxHttpHeaderSize / header.length() + 1);
             int arraySize = 1;
diff --git a/test/org/apache/tomcat/util/net/TestCustomSsl.java 
b/test/org/apache/tomcat/util/net/TestCustomSsl.java
index 0411b6f..db104e0 100644
--- a/test/org/apache/tomcat/util/net/TestCustomSsl.java
+++ b/test/org/apache/tomcat/util/net/TestCustomSsl.java
@@ -60,8 +60,7 @@ public class TestCustomSsl extends TomcatBaseTest {
 
         File keystoreFile =
             new File("test/" + TesterSupport.LOCALHOST_JKS);
-        connector.setAttribute(
-                "keystoreFile", keystoreFile.getAbsolutePath());
+        Assert.assertTrue(connector.setProperty("keystoreFile", 
keystoreFile.getAbsolutePath()));
 
         connector.setSecure(true);
         connector.setProperty("SSLEnabled", "true");
@@ -110,8 +109,8 @@ public class TestCustomSsl extends TomcatBaseTest {
             Assert.fail("Unexpected handler type");
         }
         if (serverTrustAll) {
-            tomcat.getConnector().setAttribute("trustManagerClassName",
-                    "org.apache.tomcat.util.net.TesterSupport$TrustAllCerts");
+            
Assert.assertTrue(tomcat.getConnector().setProperty("trustManagerClassName",
+                    "org.apache.tomcat.util.net.TesterSupport$TrustAllCerts"));
         }
 
         // Start Tomcat
diff --git a/test/org/apache/tomcat/util/net/TesterSupport.java 
b/test/org/apache/tomcat/util/net/TesterSupport.java
index b402f24..2b14955 100644
--- a/test/org/apache/tomcat/util/net/TesterSupport.java
+++ b/test/org/apache/tomcat/util/net/TesterSupport.java
@@ -47,6 +47,8 @@ import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.junit.Assert;
+
 import org.apache.catalina.Context;
 import org.apache.catalina.authenticator.SSLAuthenticator;
 import org.apache.catalina.connector.Connector;
@@ -127,33 +129,31 @@ public final class TesterSupport {
             connector.setProperty("sslProtocol", "tls");
             java.net.URL keyStoreUrl = cl.getResource(keystore);
             File keystoreFile = toFile(keyStoreUrl);
-            connector.setAttribute("keystoreFile",
-                    keystoreFile.getAbsolutePath());
+            Assert.assertTrue(connector.setProperty("keystoreFile", 
keystoreFile.getAbsolutePath()));
             java.net.URL truststoreUrl = cl.getResource(CA_JKS);
             File truststoreFile = toFile(truststoreUrl);
-            connector.setAttribute("truststoreFile",
-                    truststoreFile.getAbsolutePath());
+            Assert.assertTrue(connector.setProperty("truststoreFile", 
truststoreFile.getAbsolutePath()));
 
             if (keystorePass != null) {
-                connector.setAttribute("keystorePass", keystorePass);
+                Assert.assertTrue(connector.setProperty("keystorePass", 
keystorePass));
             }
             if (keyPass != null) {
-                connector.setAttribute("keyPass", keyPass);
+                Assert.assertTrue(connector.setProperty("keyPass", keyPass));
             }
         } else {
             java.net.URL keyStoreUrl = cl.getResource(LOCALHOST_CERT_PEM);
             File keystoreFile = toFile(keyStoreUrl);
-            tomcat.getConnector().setAttribute("SSLCertificateFile",
-                    keystoreFile.getAbsolutePath());
+            
Assert.assertTrue(tomcat.getConnector().setProperty("SSLCertificateFile",
+                    keystoreFile.getAbsolutePath()));
 
             java.net.URL sslCertificateKeyUrl = 
cl.getResource(LOCALHOST_KEY_PEM);
             File sslCertificateKeyFile = toFile(sslCertificateKeyUrl);
-            tomcat.getConnector().setAttribute("SSLCertificateKeyFile",
-                    sslCertificateKeyFile.getAbsolutePath());
+            
Assert.assertTrue(tomcat.getConnector().setProperty("SSLCertificateKeyFile",
+                    sslCertificateKeyFile.getAbsolutePath()));
 
             java.net.URL caUrl = cl.getResource(TesterSupport.CA_CERT_PEM);
             File caFile = toFile(caUrl);
-            tomcat.getConnector().setAttribute("SSLCACertificateFile", 
caFile.getAbsolutePath());
+            
Assert.assertTrue(tomcat.getConnector().setProperty("SSLCACertificateFile", 
caFile.getAbsolutePath()));
         }
         tomcat.getConnector().setSecure(true);
         tomcat.getConnector().setProperty("SSLEnabled", "true");


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to