Index: HttpMethodBase.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v
retrieving revision 1.161
diff -u -r1.161 HttpMethodBase.java
--- HttpMethodBase.java 8 Jul 2003 11:51:45 -0000 1.161
+++ HttpMethodBase.java 8 Jul 2003 14:27:28 -0000
@@ -258,6 +258,9 @@
/** true if we are finished with the connection */
private boolean doneWithConnection = false;
+ /** true if the connection must be closed when no longer needed */
+ private boolean connectionCloseForced = false;
+
/** Number of milliseconds to wait for 100-contunue response. */
private static final int RESPONSE_WAIT_TIME_MS = 3000;
@@ -843,6 +846,27 @@
}
/**
+ * Tests if the connection should be force-closed when no longer needed.
+ *
+ * @return true if the connection must be closed
+ */
+ protected boolean isConnectionCloseForced() {
+ return this.connectionCloseForced;
+ }
+
+ /**
+ * Sets whether or not the connection should be force-closed when no longer
+ * needed. This value should only be set to true in abnormal
+ * circumstances.
+ *
+ * @param b true if the connection must be closed, false
+ * otherwise.
+ */
+ protected void setConnectionCloseForced(boolean b) {
+ this.connectionCloseForced = b;
+ }
+
+ /**
* Return true if we should close the connection now. The connection will
* only be left open if we are using HTTP1.1 or if "Connection: keep-alive"
* was sent.
@@ -853,11 +877,9 @@
*/
protected boolean shouldCloseConnection(HttpConnection conn) {
- // if we are not chunked and there is no content length the connection
- // cannot be reused
- if (responseHeaders.getFirstHeader("Transfer-Encoding") == null
- && getResponseContentLength() < 0) {
- LOG.debug("Should close connection as content-length is missing.");
+ // Connection must be closed due to an abnormal circumstance
+ if (isConnectionCloseForced()) {
+ LOG.debug("Should forcefully close connection.");
return true;
}
@@ -1268,6 +1290,7 @@
recoverableExceptionCount = 0;
inExecute = false;
doneWithConnection = false;
+ connectionCloseForced = false;
}
/**
@@ -2053,14 +2076,16 @@
LOG.warn("Transfer-Encoding is set but does not contain \"chunked\": "
+ getResponseHeader("Transfer-Encoding"));
}
- // we assume that the response connection will be terminated by closing
+ // The connection must be terminated by closing
// the socket as per RFC 2616, 3.6
+ setConnectionCloseForced(true);
result = is;
}
} else {
int expectedLength = getResponseContentLength();
if (expectedLength == -1) {
if (canResponseHaveBody(statusLine.getStatusCode())) {
+ setConnectionCloseForced(true);
result = is;
}
} else {