This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 9.0.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit 40f82e1a72c29d641fe99e14663a88f3ca5da5b4 Author: Mark Thomas <ma...@apache.org> 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 ca83d2ccc0..fdf37b6733 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 1491ab6d87..d20136d680 100644 --- a/test/org/apache/catalina/startup/SimpleHttpClient.java +++ b/test/org/apache/catalina/startup/SimpleHttpClient.java @@ -146,6 +146,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; } @@ -319,11 +326,12 @@ public abstract class SimpleHttpClient { Assert.assertEquals(contentLength, read); builder.append(body); } 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 99e25601f7..f67ba1f0b8 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 a26a7f96a5..94a3323b3d 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: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org