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.136 diff -u -r1.136 HttpMethodBase.java --- java/org/apache/commons/httpclient/HttpMethodBase.java 22 Apr 2003 17:25:40 -0000 1.136 +++ java/org/apache/commons/httpclient/HttpMethodBase.java 23 Apr 2003 01:17:10 -0000 @@ -860,24 +860,37 @@ /** * Return true if we should close the connection now. The connection will - * only be left open if we are using HTTP1.1 + * only be left open if we are using HTTP1.1 or if "Connection: keep-alive" + * was sent. + * * @return boolean true if we should close the connection. */ protected boolean shouldCloseConnection() { - if (!http11) { - LOG.debug("Should close connection since using HTTP/1.0."); - return true; - } else { - Header connectionHeader = getResponseHeader("connection"); - if (null != connectionHeader - && "close".equalsIgnoreCase(connectionHeader.getValue())) { - LOG.debug("Should close connection since \"Connection: close\" header found."); + + Header connectionHeader = getResponseHeader("connection"); + // handle the connection header value, if present + if (connectionHeader != null) { + if (connectionHeader.getValue().equalsIgnoreCase("close")) { + LOG.debug("Should close connection since \"Connection: close\" was found."); return true; + } else if (connectionHeader.getValue().equalsIgnoreCase("keep-alive")) { + LOG.debug("Should NOT close connection since \"Connection: keep-alive\" " + + "was found."); + return false; + } else { + LOG.debug("Unknown \"Connection\" header value: " + connectionHeader.getValue() + + ". Resorting to protocol version default close policy."); } } - return false; + + // missing or invalid connection header, do the default + if (http11) { + LOG.debug("Should NOT close connection, using HTTP/1.1."); + } else { + LOG.debug("Should close connection, using HTTP/1.0."); + } + return !http11; } - /** * Return true if a retry is needed.