You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2011/04/06 18:37:21 UTC

svn commit: r1089529 - /tomcat/trunk/test/org/apache/catalina/startup/SimpleHttpClient.java

Author: markt
Date: Wed Apr  6 16:37:21 2011
New Revision: 1089529

URL: http://svn.apache.org/viewvc?rev=1089529&view=rev
Log:
Need option to use content length for correct processing of pipelined requests.

Modified:
    tomcat/trunk/test/org/apache/catalina/startup/SimpleHttpClient.java

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=1089529&r1=1089528&r2=1089529&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/startup/SimpleHttpClient.java (original)
+++ tomcat/trunk/test/org/apache/catalina/startup/SimpleHttpClient.java Wed Apr  6 16:37:21 2011
@@ -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();



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