olegk 2003/11/03 14:40:29
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 TestHttpConnection.java
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
No revision
No revision
1.159.2.17 +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.159.2.16
retrieving revision 1.159.2.17
diff -u -r1.159.2.16 -r1.159.2.17
--- HttpMethodBase.java 21 Oct 2003 20:15:03 -0000 1.159.2.16
+++ HttpMethodBase.java 3 Nov 2003 22:40:29 -0000 1.159.2.17
@@ -1080,6 +1080,7 @@
// Discard status line
this.statusLine = null;
+ this.connectionCloseForced = false;
//write the request and read the response, will retry
processRequest(state, conn);
@@ -2069,8 +2070,15 @@
int 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 {
@@ -2746,6 +2754,7 @@
responseConnection.close();
}
}
+ this.connectionCloseForced = false;
doneWithConnection = true;
if (!inExecute) {
ensureConnectionRelease();
No revision
No revision
1.8.2.1 +4 -4
jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestHttpConnection.java
Index: TestHttpConnection.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestHttpConnection.java,v
retrieving revision 1.8
retrieving revision 1.8.2.1
diff -u -r1.8 -r1.8.2.1
1.8.2.1 +32 -16
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
retrieving revision 1.8.2.1
diff -u -r1.8 -r1.8.2.1
--- TestResponseHeaders.java 20 Jun 2003 13:33:09 -0000 1.8
+++ TestResponseHeaders.java 3 Nov 2003 22:40:29 -0000 1.8.2.1
@@ -96,18 +96,6 @@
- /**
- * Simple extension of HttpMethodBase.
- */
- private class SimpleHttpMethod extends HttpMethodBase {
- public SimpleHttpMethod() {
- super("");
- }
- public String getName() {
- return "simple";
- }
- }
-
// ----------------------------------------------------------- Test Methods
public void testHeaders() throws Exception {
String body = "XXX\r\nYYY\r\nZZZ";
@@ -310,4 +298,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";
+ HttpState state = new HttpState();
+ SimpleHttpMethod method = new SimpleHttpMethod();
+ SimpleHttpConnection conn = new SimpleHttpConnection(headers, body);
+ method.execute(state, conn);
+ 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";
+ HttpState state = new HttpState();
+ SimpleHttpMethod method = new SimpleHttpMethod();
+ SimpleHttpConnection conn = new SimpleHttpConnection(headers, body);
+ method.execute(state, conn);
+ assertTrue("Connection should be closed",
method.shouldCloseConnection(conn));
+ assertFalse("Connection should NOT be closed",
method.isConnectionCloseForced());
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]