commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From oglu...@apache.org
Subject cvs commit: jakarta-commons/httpclient/src/test/org/apache/commons/httpclient TestMethodsNoHost.java
Date Fri, 11 Oct 2002 08:34:32 GMT
oglueck     2002/10/11 01:34:32

  Modified:    httpclient/src/java/org/apache/commons/httpclient
                        HttpMethodBase.java
               httpclient/src/test/org/apache/commons/httpclient
                        TestMethodsNoHost.java
  Log:
  Handling presence of both Transfer-Encoding and Content-Length header correctly.
  Patch by Ryan Hoegg
  added test case
  
  Revision  Changes    Path
  1.62      +12 -10    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.61
  retrieving revision 1.62
  diff -u -r1.61 -r1.62
  --- HttpMethodBase.java	24 Sep 2002 02:53:27 -0000	1.61
  +++ HttpMethodBase.java	11 Oct 2002 08:34:31 -0000	1.62
  @@ -1065,7 +1065,7 @@
       }
   
       /**
  -     * Adds a <tt>Content-Length</tt> or <tt>Transer-Encoding: Chunked</tt>
  +     * Adds a <tt>Content-Length</tt> or <tt>Transfer-Encoding: Chunked</tt>
        * request header, as long as no <tt>Content-Length</tt> request header
        * already exists.
        * 
  @@ -1532,16 +1532,18 @@
               is = new WireLogInputStream(is);
           }
           InputStream result = null;
  -        if (null != lengthHeader) {
  +        // We use Transfer-Encoding if present and ignore Content-Length.
  +        // RFC2616, 4.4 item number 3
  +        if (null != transferEncodingHeader) {
  +            if ("chunked".equalsIgnoreCase(transferEncodingHeader.getValue())) {
  +                result = new ChunkedInputStream(is, this);
  +            }
  +        } else if (null != lengthHeader) {
               try {
                   int expectedLength = Integer.parseInt(lengthHeader.getValue());
                   result = new ContentLengthInputStream(is, expectedLength);
               } catch(NumberFormatException e) {
                   // ignored
  -            }
  -        } else if (null != transferEncodingHeader) {
  -            if ("chunked".equalsIgnoreCase(transferEncodingHeader.getValue())) {
  -                result = new ChunkedInputStream(is, this);
               }
           } else if(canResponseHaveBody(statusLine.getStatusCode()) 
                   && !getName().equals(ConnectMethod.NAME)){
  
  
  
  1.8       +21 -4     jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestMethodsNoHost.java
  
  Index: TestMethodsNoHost.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestMethodsNoHost.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- TestMethodsNoHost.java	6 Aug 2002 15:15:32 -0000	1.7
  +++ TestMethodsNoHost.java	11 Oct 2002 08:34:32 -0000	1.8
  @@ -257,6 +257,23 @@
           assertEquals("/some/path/", simple.getPath());
       }
   
  +    /** Tests response with a Trasfer-Encoding and Content-Length */
  +    public void testHttpMethodBaseTEandCL() throws Exception {
  +        SimpleHttpConnection conn = new SimpleHttpConnection();
  +        String headers = "HTTP/1.1 200 OK\r\n"
  +                       +"Date: Wed, 28 Mar 2001 05:05:04 GMT\r\n"
  +                       +"Connection: close\r\n"
  +                       +"Transfer-Encoding: chunked\r\n"
  +                       +"Content-Length: 1\r\n";
  +        String body = "0a\r\n1234567890\r\n3\r\n123\r\n0\r\n";
  +        conn.addResponse(headers, body);
  +        conn.open();
  +        HttpMethodBase method = new GetMethod("/");
  +        method.execute(new HttpState(), conn);
  +        String responseBody = method.getResponseBodyAsString();
  +        conn.close();
  +        assertEquals("1234567890123", responseBody);
  +    }
   
   
   
  
  
  

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


Mime
View raw message