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 Mon, 03 Nov 2003 23:03:02 GMT
olegk       2003/11/03 15:03:02

  Modified:    httpclient/src/java/org/apache/commons/httpclient
                        HttpMethodBase.java
               httpclient/src/test/org/apache/commons/httpclient
                        TestResponseHeaders.java
  Log:
  PR #24327 (MS Proxy with NTLM authentication set up does not work)
  
  Fixes the severe bug of HttpClient not resetting the 'force-close connection' flag, if the
HTTP method is automatically retried (for instance, when automatically handling authentication
challenge)
  
  Contributed by Oleg Kalnichevski
  
  Revision  Changes    Path
  1.188     +15 -6     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.187
  retrieving revision 1.188
  diff -u -r1.187 -r1.188
  --- HttpMethodBase.java	2 Nov 2003 12:10:28 -0000	1.187
  +++ HttpMethodBase.java	3 Nov 2003 23:03:02 -0000	1.188
  @@ -988,6 +988,7 @@
   
           checkExecuteConditions(state, conn);
           this.statusLine = null;
  +        this.connectionCloseForced = false;
   
           conn.setLastResponseInputStream(null);
   
  @@ -1731,8 +1732,15 @@
               long expectedLength = getResponseContentLength();
               if (expectedLength == -1) {
                   if (canResponseHaveBody(statusLine.getStatusCode())) {
  -                    LOG.warn("Response content length is not known");
  -                    setConnectionCloseForced(true);
  +                    Header connectionHeader = responseHeaders.getFirstHeader("Connection");
  +                    String connectionDirective = null;
  +                    if (connectionHeader != null) {
  +                        connectionDirective = connectionHeader.getValue();
  +                    }
  +                    if (!"close".equalsIgnoreCase(connectionDirective)) {
  +                        LOG.warn("Response content length is not known");
  +                        setConnectionCloseForced(true);
  +                    }
                       result = is;            
                   }
               } else {
  @@ -2241,6 +2249,7 @@
                   responseConnection.close();
               }
           }
  +        this.connectionCloseForced = false;
           ensureConnectionRelease();
       }
   
  
  
  
  1.11      +32 -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.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- TestResponseHeaders.java	6 Sep 2003 14:41:25 -0000	1.10
  +++ TestResponseHeaders.java	3 Nov 2003 23:03:02 -0000	1.11
  @@ -282,4 +282,32 @@
           assertEquals("UserLand Frontier/7.0-WinNT", method.getResponseHeader("Server").getValue());
           assertTrue(method.getResponseHeader("Content-Type").toString().indexOf("boundary")
!= -1);
       }
  +
  +
  +	public void testForceCloseConnection() throws Exception {
  +		String body = "stuff";
  +		String headers =
  +				"HTTP/1.1 200 OK\r\n" +
  +				"Content-Type: garbage\r\n" +
  +                "\r\n";
  +		SimpleHttpMethod method = new SimpleHttpMethod();
  +        conn.addResponse(headers, body);
  +        client.executeMethod(method);
  +		assertTrue("Connection should be closed", method.shouldCloseConnection(conn));
  +		assertTrue("Connection should be force-closed", method.isConnectionCloseForced());
  +	}
  +    
  +	public void testForceCloseConnection2() throws Exception {
  +		String body = "stuff";
  +		String headers =
  +				"HTTP/1.1 200 OK\r\n" +
  +				"Content-Type: garbage\r\n" +
  +				"Connection: close\r\n" +
  +                "\r\n";
  +		SimpleHttpMethod method = new SimpleHttpMethod();
  +        conn.addResponse(headers, body);
  +        client.executeMethod(method);
  +		assertTrue("Connection should be closed", method.shouldCloseConnection(conn));
  +		assertFalse("Connection should NOT be closed", method.isConnectionCloseForced());
  +	}
   }
  
  
  

---------------------------------------------------------------------
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