Index: java/org/apache/commons/httpclient/HttpMethodBase.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v retrieving revision 1.159.2.24 diff -u -r1.159.2.24 HttpMethodBase.java --- java/org/apache/commons/httpclient/HttpMethodBase.java 22 Feb 2004 18:21:13 -0000 1.159.2.24 +++ java/org/apache/commons/httpclient/HttpMethodBase.java 25 Feb 2004 22:10:40 -0000 @@ -1,5 +1,5 @@ /* - * $Header: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v 1.159.2.24 2004/02/22 18:21:13 olegk Exp $ + * $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v 1.159.2.24 2004/02/22 18:21:13 olegk Exp $ * $Revision: 1.159.2.24 $ * $Date: 2004/02/22 18:21:13 $ * @@ -652,7 +652,7 @@ if (headers.length > 1) { LOG.warn("Multiple content-length headers detected"); } - for (int i = headers.length - 1; i >= 0; i++) { + for (int i = headers.length - 1; i >= 0; i--) { Header header = headers[i]; try { return Integer.parseInt(header.getValue()); Index: test/org/apache/commons/httpclient/TestResponseHeaders.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestResponseHeaders.java,v retrieving revision 1.8.2.2 diff -u -r1.8.2.2 TestResponseHeaders.java --- test/org/apache/commons/httpclient/TestResponseHeaders.java 22 Feb 2004 18:21:16 -0000 1.8.2.2 +++ test/org/apache/commons/httpclient/TestResponseHeaders.java 25 Feb 2004 22:10:44 -0000 @@ -1,5 +1,5 @@ /* - * $Header: /home/cvspublic/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestResponseHeaders.java,v 1.8.2.2 2004/02/22 18:21:16 olegk Exp $ + * $Header: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestResponseHeaders.java,v 1.8.2.2 2004/02/22 18:21:16 olegk Exp $ * $Revision: 1.8.2.2 $ * $Date: 2004/02/22 18:21:16 $ * ==================================================================== @@ -198,6 +198,36 @@ method.getResponseBodyAsString(); assertFalse(conn.isOpen()); + } + + public void testInvalidContentLength1() throws Exception { + // test with connection header + SimpleHttpConnection conn = new SimpleHttpConnection(); + String headers = "HTTP/1.1 200 OK\r\n" + + "Content-Length: 5\r\n" + + "Content-Length: stuff\r\n" + + "\r\n"; + + // test with connection header + conn.addResponse(headers, "12345"); + GetMethod method = new GetMethod("/"); + method.execute(new HttpState(), conn); + assertEquals(5, method.getResponseContentLength()); + } + + public void testInvalidContentLength2() throws Exception { + // test with connection header + SimpleHttpConnection conn = new SimpleHttpConnection(); + String headers = "HTTP/1.1 200 OK\r\n" + + "Content-Length: stuff\r\n" + + "Content-Length: 5\r\n" + + "\r\n"; + + // test with connection header + conn.addResponse(headers, "12345"); + GetMethod method = new GetMethod("/"); + method.execute(new HttpState(), conn); + assertEquals(5, method.getResponseContentLength()); } public void testProxyNoContentLength() throws Exception {