Need option to use content length for correct processing of pipelined requests.
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 6 Apr 2011 16:37:21 +0000 (16:37 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 6 Apr 2011 16:37:21 +0000 (16:37 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1089529 13f79535-47bb-0310-9956-ffa450edef68

test/org/apache/catalina/startup/SimpleHttpClient.java

index 88ed423..f4e9545 100644 (file)
@@ -67,6 +67,7 @@ public abstract class SimpleHttpClient {
     private String responseLine;
     private List<String> responseHeaders = new ArrayList<String>();
     private String responseBody;
+    private boolean useContentLength;
 
     public void setPort(int thePort) {
         port = thePort;
@@ -100,6 +101,10 @@ public abstract class SimpleHttpClient {
         return responseBody;
     }
 
+    public void setUseContentLength(boolean b) {
+        useContentLength = b;
+    }
+
     public String getSessionId() {
         for (String header : responseHeaders) {
             if (header.startsWith(SESSION_COOKIE_HEADER_PREFIX)) {
@@ -174,18 +179,28 @@ public abstract class SimpleHttpClient {
         
         // Put the headers into the map
         String line = readLine();
+        int cl = -1;
         while (line!=null && line.length() > 0) {
             responseHeaders.add(line);
             line = readLine();
+            if (line != null && line.startsWith("Content-Length: ")) {
+                cl = Integer.parseInt(line.substring(16));
+            }
         }
         
         // Read the body, if any
         StringBuilder builder = new StringBuilder();
         if (readBody) {
-            line = readLine();
-            while (line != null) {
-                builder.append(line);
+            if (cl > -1 && useContentLength) {
+                char[] body = new char[cl];
+                reader.read(body);
+                builder.append(body);
+            } else {
                 line = readLine();
+                while (line != null) {
+                    builder.append(line);
+                    line = readLine();
+                }
             }
         }
         responseBody = builder.toString();