This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch 10.1.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/10.1.x by this push:
new f631975606 Refactor SimpleHTTPClient to read body as-is rather than
via readLine()
f631975606 is described below
commit f631975606dc2d8e8a77cc61bfa96930d928b009
Author: Mark Thomas <[email protected]>
AuthorDate: Thu Jun 22 17:08:02 2023 +0100
Refactor SimpleHTTPClient to read body as-is rather than via readLine()
Update impacted tests so they still pass
---
test/org/apache/catalina/core/TestStandardContext.java | 2 +-
test/org/apache/catalina/startup/SimpleHttpClient.java | 16 ++++++++++++----
test/org/apache/coyote/http11/TestHttp11InputBuffer.java | 2 +-
test/org/apache/coyote/http11/TestHttp11Processor.java | 2 +-
4 files changed, 15 insertions(+), 7 deletions(-)
diff --git a/test/org/apache/catalina/core/TestStandardContext.java
b/test/org/apache/catalina/core/TestStandardContext.java
index aa92e22a58..9070963476 100644
--- a/test/org/apache/catalina/core/TestStandardContext.java
+++ b/test/org/apache/catalina/core/TestStandardContext.java
@@ -704,7 +704,7 @@ public class TestStandardContext extends TomcatBaseTest {
PrintWriter out = resp.getWriter();
- out.println("parts=" + (null == req.getParts()
+ out.print("parts=" + (null == req.getParts()
? "null"
: Integer.valueOf(req.getParts().size())));
}
diff --git a/test/org/apache/catalina/startup/SimpleHttpClient.java
b/test/org/apache/catalina/startup/SimpleHttpClient.java
index bc47ada2b0..00943970d5 100644
--- a/test/org/apache/catalina/startup/SimpleHttpClient.java
+++ b/test/org/apache/catalina/startup/SimpleHttpClient.java
@@ -150,6 +150,13 @@ public abstract class SimpleHttpClient {
return responseLine;
}
+ public int getStatusCode() {
+ if (responseLine.length() < 13) {
+ throw new IllegalStateException();
+ }
+ return Integer.parseInt(responseLine.substring(9, 12));
+ }
+
public List<String> getResponseHeaders() {
return responseHeaders;
}
@@ -326,11 +333,12 @@ public abstract class SimpleHttpClient {
builder.append(body, 0 , read);
Assert.assertEquals(contentLength,
builder.toString().getBytes(responseBodyEncoding).length);
} else {
- // not using content length, so just read it line by line
- String line = null;
+ // Not using content length, so just read until EOF
+ char[] buf = new char[1024];
+ int read;
try {
- while ((line = readLine()) != null) {
- builder.append(line);
+ while ((read = reader.read(buf)) != -1) {
+ builder.append(buf, 0, read);
}
} catch (SocketException e) {
// Ignore
diff --git a/test/org/apache/coyote/http11/TestHttp11InputBuffer.java
b/test/org/apache/coyote/http11/TestHttp11InputBuffer.java
index 9796330d43..2a01bdd2cc 100644
--- a/test/org/apache/coyote/http11/TestHttp11InputBuffer.java
+++ b/test/org/apache/coyote/http11/TestHttp11InputBuffer.java
@@ -379,7 +379,7 @@ public class TestHttp11InputBuffer extends TomcatBaseTest {
private void processHeaders(String header, HttpServletRequest req,
PrintWriter out) {
Enumeration<String> values = req.getHeaders(header);
while (values.hasMoreElements()) {
- out.println(values.nextElement());
+ out.print(values.nextElement());
}
}
}
diff --git a/test/org/apache/coyote/http11/TestHttp11Processor.java
b/test/org/apache/coyote/http11/TestHttp11Processor.java
index 65b2015c71..857d51185d 100644
--- a/test/org/apache/coyote/http11/TestHttp11Processor.java
+++ b/test/org/apache/coyote/http11/TestHttp11Processor.java
@@ -105,7 +105,7 @@ public class TestHttp11Processor extends TomcatBaseTest {
// There should not be an end chunk
Assert.assertFalse(client.getResponseBody().endsWith("0"));
// The last portion of text should be there
- Assert.assertTrue(client.getResponseBody().endsWith("line03"));
+ Assert.assertTrue(client.getResponseBody().endsWith("line03" +
SimpleHttpClient.CRLF));
}
private static class ResponseWithErrorServlet extends HttpServlet {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]