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.177 diff -u -r1.177 HttpMethodBase.java --- java/org/apache/commons/httpclient/HttpMethodBase.java 12 Aug 2003 02:55:22 -0000 1.177 +++ java/org/apache/commons/httpclient/HttpMethodBase.java 3 Sep 2003 01:56:49 -0000 @@ -1222,12 +1222,6 @@ } int port = conn.getPort(); - if (getRequestHeader("host") != null) { - LOG.debug( - "Request to add Host header ignored: header already added"); - return; - } - // Note: RFC 2616 uses the term "internet host name" for what goes on the // host line. It would seem to imply that host should be blank if the // host is a number instead of an name. Based on the behavior of web Index: test/org/apache/commons/httpclient/NoHostHttpConnectionManager.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/NoHostHttpConnectionManager.java,v retrieving revision 1.1 diff -u -r1.1 NoHostHttpConnectionManager.java --- test/org/apache/commons/httpclient/NoHostHttpConnectionManager.java 12 Aug 2003 02:35:17 -0000 1.1 +++ test/org/apache/commons/httpclient/NoHostHttpConnectionManager.java 3 Sep 2003 01:56:52 -0000 @@ -20,7 +20,7 @@ private HttpConnection connection; public NoHostHttpConnectionManager() { - this.connection = new SimpleHttpConnection(); + setConnection(new SimpleHttpConnection()); } /** @@ -28,22 +28,45 @@ */ public void setConnection(HttpConnection connection) { this.connection = connection; + connection.setHttpConnectionManager(this); } public HttpConnection getConnection(HostConfiguration hostConfiguration) { + + // make sure the host and proxy are correct for this connection + // close it and set the values if they are not + if (!hostConfiguration.hostEquals(connection) + || !hostConfiguration.proxyEquals(connection)) { + + if (connection.isOpen()) { + connection.close(); + } + + connection.setHost(hostConfiguration.getHost()); + connection.setVirtualHost(hostConfiguration.getVirtualHost()); + connection.setPort(hostConfiguration.getPort()); + connection.setProtocol(hostConfiguration.getProtocol()); + connection.setLocalAddress(hostConfiguration.getLocalAddress()); + + connection.setProxyHost(hostConfiguration.getProxyHost()); + connection.setProxyPort(hostConfiguration.getProxyPort()); + } else { + finishLastResponse(connection); + } + return connection; } public HttpConnection getConnection(HostConfiguration hostConfiguration, long timeout) throws HttpException { - return connection; + return getConnection(hostConfiguration); } public HttpConnection getConnectionWithTimeout( HostConfiguration hostConfiguration, long timeout) throws ConnectTimeoutException { - return connection; + return getConnection(hostConfiguration); } public void releaseConnection(HttpConnection conn) { Index: test/org/apache/commons/httpclient/TestMethodsRedirectNoHost.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestMethodsRedirectNoHost.java,v retrieving revision 1.7 diff -u -r1.7 TestMethodsRedirectNoHost.java --- test/org/apache/commons/httpclient/TestMethodsRedirectNoHost.java 12 Aug 2003 02:35:17 -0000 1.7 +++ test/org/apache/commons/httpclient/TestMethodsRedirectNoHost.java 3 Sep 2003 01:56:54 -0000 @@ -209,17 +209,16 @@ } public void testRedirectDifferentHost() throws Exception { - conn = new SimpleHttpConnection("oldhost", 80); + addRedirectResponse("http://newhost/newfile"); addOkResponse(); - conn.open(); HttpMethod method = new SimpleHttpMethod("/oldfile"); method.setFollowRedirects(true); - method.execute(new HttpState(), conn); - Header locationHeader = method.getResponseHeader("Location"); - assertEquals(302, method.getStatusCode()); - assertEquals("/oldfile", method.getPath()); + client.executeMethod(method); + assertEquals(200, method.getStatusCode()); + assertEquals("/newfile", method.getPath()); + assertEquals("newhost", method.getRequestHeader("host").getValue()); } public void testRedirectDifferentPort() throws Exception {