Test cases for bug49424 based on a patch by Earl Nolan
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 10 Jun 2010 19:58:02 +0000 (19:58 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 10 Jun 2010 19:58:02 +0000 (19:58 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@953433 13f79535-47bb-0310-9956-ffa450edef68

test/org/apache/catalina/connector/TestRequest.java

index 73a0d72..e430495 100644 (file)
 package org.apache.catalina.connector;
 
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.PrintWriter;
+import java.net.HttpURLConnection;
+import java.net.URL;
 import java.util.Enumeration;
 
 import javax.servlet.ServletException;
@@ -256,4 +259,46 @@ public class TestRequest extends TomcatBaseTest {
         }
         
     }
+    
+    public void testBug49424NoChunking() throws Exception {
+        Tomcat tomcat = getTomcatInstance();
+        Context root = tomcat.addContext("",
+                System.getProperty("java.io.tmpdir"));
+        Tomcat.addServlet(root, "Bug37794", new Bug37794Servlet());
+        root.addServletMapping("/", "Bug37794");
+        tomcat.start();
+
+        HttpURLConnection conn = getConnection();
+        InputStream is = conn.getInputStream();
+        assertNotNull(is);
+    }
+
+    public void testBug49424WithChunking() throws Exception {
+        Tomcat tomcat = getTomcatInstance();
+        Context root = tomcat.addContext("",
+                System.getProperty("java.io.tmpdir"));
+        Tomcat.addServlet(root, "Bug37794", new Bug37794Servlet());
+        root.addServletMapping("/", "Bug37794");
+        tomcat.start();
+        
+        HttpURLConnection conn = getConnection();
+        conn.setChunkedStreamingMode(8 * 1024);
+        InputStream is = conn.getInputStream();
+        assertNotNull(is);
+    }
+
+    private HttpURLConnection getConnection() throws IOException {
+        final String query = "http://localhost:" + getPort() + "/";
+        URL postURL;
+        postURL = new URL(query);
+        HttpURLConnection conn = (HttpURLConnection) postURL.openConnection();
+        conn.setRequestMethod("POST");
+
+        conn.setDoInput(true);
+        conn.setDoOutput(true);
+        conn.setUseCaches(false);
+        conn.setAllowUserInteraction(false);
+
+        return conn;
+    }
 }