Index: java/org/apache/commons/httpclient/HttpMethodBase.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v retrieving revision 1.220 diff -u -r1.220 HttpMethodBase.java --- java/org/apache/commons/httpclient/HttpMethodBase.java 9 Nov 2004 19:25:42 -0000 1.220 +++ java/org/apache/commons/httpclient/HttpMethodBase.java 19 Dec 2004 22:26:38 -0000 @@ -1,5 +1,5 @@ /* - * $Header: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v 1.220 2004/11/09 19:25:42 olegk Exp $ + * $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v 1.220 2004/11/09 19:25:42 olegk Exp $ * $Revision: 1.220 $ * $Date: 2004/11/09 19:25:42 $ * @@ -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 { Index: test/org/apache/commons/httpclient/TestConnectionPersistence.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestConnectionPersistence.java,v retrieving revision 1.1 diff -u -r1.1 TestConnectionPersistence.java --- test/org/apache/commons/httpclient/TestConnectionPersistence.java 7 Nov 2004 12:31:42 -0000 1.1 +++ test/org/apache/commons/httpclient/TestConnectionPersistence.java 19 Dec 2004 22:26:40 -0000 @@ -1,5 +1,5 @@ /* - * $Header: /home/cvspublic/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestConnectionPersistence.java,v 1.1 2004/11/07 12:31:42 olegk Exp $ + * $Header: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestConnectionPersistence.java,v 1.1 2004/11/07 12:31:42 olegk Exp $ * $Revision: 1.1 $ * $Date: 2004/11/07 12:31:42 $ * ==================================================================== @@ -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()); } }