private String responseLine;
private List<String> responseHeaders = new ArrayList<String>();
private String responseBody;
+ private boolean useContentLength;
public void setPort(int thePort) {
port = thePort;
return responseBody;
}
+ public void setUseContentLength(boolean b) {
+ useContentLength = b;
+ }
+
public String getSessionId() {
for (String header : responseHeaders) {
if (header.startsWith(SESSION_COOKIE_HEADER_PREFIX)) {
// 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();