From 3ce7f1a867c3ae9e888df9cba4c501e02f34969c Mon Sep 17 00:00:00 2001 From: markt Date: Wed, 6 Apr 2011 16:37:21 +0000 Subject: [PATCH] Need option to use content length for correct processing of pipelined requests. git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1089529 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/catalina/startup/SimpleHttpClient.java | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/test/org/apache/catalina/startup/SimpleHttpClient.java b/test/org/apache/catalina/startup/SimpleHttpClient.java index 88ed4235f..f4e954529 100644 --- a/test/org/apache/catalina/startup/SimpleHttpClient.java +++ b/test/org/apache/catalina/startup/SimpleHttpClient.java @@ -67,6 +67,7 @@ public abstract class SimpleHttpClient { private String responseLine; private List responseHeaders = new ArrayList(); 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(); -- 2.11.0