commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject cvs commit: jakarta-commons/httpclient/src/test/org/apache/commons/httpclient TestResponseHeaders.java
Date Thu, 26 Feb 2004 20:26:46 GMT
olegk       2004/02/26 12:26:46

  Modified:    httpclient/src/java/org/apache/commons/httpclient Tag:
                        HTTPCLIENT_2_0_BRANCH HttpMethodBase.java
               httpclient/src/test/org/apache/commons/httpclient Tag:
                        HTTPCLIENT_2_0_BRANCH TestResponseHeaders.java
  Log:
  PR #27237 (ArrayIndexOutOfBounds Exception on invalid content-length)
  
  Contributed by Oleg Kalnichevski
  Reviewed by Michael Becke
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.159.2.25 +5 -5      jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java
  
  Index: HttpMethodBase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v
  retrieving revision 1.159.2.24
  retrieving revision 1.159.2.25
  diff -u -r1.159.2.24 -r1.159.2.25
  --- HttpMethodBase.java	22 Feb 2004 18:21:13 -0000	1.159.2.24
  +++ HttpMethodBase.java	26 Feb 2004 20:26:45 -0000	1.159.2.25
  @@ -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());
  
  
  
  No                   revision
  No                   revision
  1.8.2.3   +34 -4     jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestResponseHeaders.java
  
  Index: TestResponseHeaders.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestResponseHeaders.java,v
  retrieving revision 1.8.2.2
  retrieving revision 1.8.2.3
  diff -u -r1.8.2.2 -r1.8.2.3
  --- TestResponseHeaders.java	22 Feb 2004 18:21:16 -0000	1.8.2.2
  +++ TestResponseHeaders.java	26 Feb 2004 20:26:46 -0000	1.8.2.3
  @@ -200,6 +200,36 @@
           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 {
           // test with proxy-connection header
           SimpleHttpConnection conn = new SimpleHttpConnection();
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message