olegk 2004/12/20 03:42:30
Modified: httpclient/src/java/org/apache/commons/httpclient
HttpMethodBase.java
httpclient/src/test/org/apache/commons/httpclient
TestConnectionPersistence.java
Log:
PR #32333 (Connection not closed after "Connection: close" request)
Contributed by Oleg Kalnichevski
Reviewed by Michael Becke
Revision Changes Path
1.221 +13 -8
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.220
retrieving revision 1.221
diff -u -r1.220 -r1.221
--- HttpMethodBase.java 9 Nov 2004 19:25:42 -0000 1.220
+++ HttpMethodBase.java 20 Dec 2004 11:42:30 -0000 1.221
@@ -903,17 +903,22 @@
if (connectionHeader == null) {
connectionHeader = responseHeaders.getFirstHeader("connection");
}
+ // In case the response does not contain any explict connection
+ // directives, check whether the request does
+ if (connectionHeader == null) {
+ connectionHeader = requestHeaders.getFirstHeader("connection");
+ }
if (connectionHeader != null) {
if (connectionHeader.getValue().equalsIgnoreCase("close")) {
if (LOG.isDebugEnabled()) {
- LOG.debug("Should close connection in response to "
- + connectionHeader.toExternalForm());
+ LOG.debug("Should close connection in response to
directive: "
+ + connectionHeader.getValue());
}
return true;
} else if
(connectionHeader.getValue().equalsIgnoreCase("keep-alive")) {
if (LOG.isDebugEnabled()) {
- LOG.debug("Should NOT close connection in response to "
- + connectionHeader.toExternalForm());
+ LOG.debug("Should NOT close connection in response to
directive: "
+ + connectionHeader.getValue());
}
return false;
} else {
1.2 +46 -4
jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestConnectionPersistence.java
Index: TestConnectionPersistence.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestConnectionPersistence.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TestConnectionPersistence.java 7 Nov 2004 12:31:42 -0000 1.1
+++ TestConnectionPersistence.java 20 Dec 2004 11:42:30 -0000 1.2
@@ -31,6 +31,10 @@
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.StringRequestEntity;
+import org.apache.commons.httpclient.server.HttpRequestHandler;
+import org.apache.commons.httpclient.server.SimpleHttpServerConnection;
+import org.apache.commons.httpclient.server.SimpleRequest;
+import org.apache.commons.httpclient.server.SimpleResponse;
import junit.framework.Test;
import junit.framework.TestSuite;
@@ -171,6 +175,44 @@
httppost.releaseConnection();
}
assertTrue(connman.getConection().isOpen());
+ }
+
+ public void testRequestConnClose() throws Exception {
+ this.server.setRequestHandler(new HttpRequestHandler() {
+
+ public boolean processRequest(
+ final SimpleHttpServerConnection conn,
+ final SimpleRequest request) throws IOException {
+
+ // Make sure the request if fully consumed
+ request.getBodyBytes();
+
+ SimpleResponse response = new SimpleResponse();
+ response.setStatusLine(HttpVersion.HTTP_1_1,
HttpStatus.SC_OK);
+ response.setBodyString("stuff back");
+
+ conn.setKeepAlive(true);
+ conn.writeResponse(response);
+
+ return true;
+ }
+
+ });
+
+ AccessibleHttpConnectionManager connman = new
AccessibleHttpConnectionManager();
+
+ this.client.getParams().setVersion(HttpVersion.HTTP_1_0);
+ this.client.setHttpConnectionManager(connman);
+
+ PostMethod httppost = new PostMethod("/test/");
+ httppost.setRequestHeader("Connection", "close");
+ httppost.setRequestEntity(new StringRequestEntity("stuff"));
+ try {
+ this.client.executeMethod(httppost);
+ } finally {
+ httppost.releaseConnection();
+ }
+ assertFalse(connman.getConection().isOpen());
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]