Index: test/org/apache/commons/httpclient/TestHttpMethodFundamentals.java =================================================================== --- test/org/apache/commons/httpclient/TestHttpMethodFundamentals.java (revision 161942) +++ test/org/apache/commons/httpclient/TestHttpMethodFundamentals.java (working copy) @@ -173,6 +173,22 @@ } } + public void testAbsoluteURLOverridesDefaultHost() throws IOException { + this.server.setHttpService(new EchoService()); + // reset default host configuration + HostConfiguration hostconfig = new HostConfiguration(); + hostconfig.setHost("somehwere.outthere.in.pampa"); + + GetMethod httpget = new GetMethod("http://" + + this.server.getLocalAddress() + ":" + this.server.getLocalPort() + "/test/"); + try { + this.client.executeMethod(hostconfig, httpget); + assertEquals(HttpStatus.SC_OK, httpget.getStatusCode()); + } finally { + httpget.releaseConnection(); + } + } + public void testAbsoluteURLHitWithDefaultHost() throws IOException { this.server.setHttpService(new EchoService()); // Somewhere out there in pampa Index: java/org/apache/commons/httpclient/HttpClient.java =================================================================== --- java/org/apache/commons/httpclient/HttpClient.java (revision 161942) +++ java/org/apache/commons/httpclient/HttpClient.java (working copy) @@ -353,7 +353,7 @@ * {@link HostConfiguration host configuration} with the given custom * {@link HttpState HTTP state}. * - * @param hostConfiguration The {@link HostConfiguration host configuration} to use. + * @param hostconfig The {@link HostConfiguration host configuration} to use. * @param method the {@link HttpMethod HTTP method} to execute. * @param state the {@link HttpState HTTP state} to use when executing the method. * If null, the state returned by {@link #getState} will be used instead. @@ -366,7 +366,7 @@ * cannot be recovered from. * @since 2.0 */ - public int executeMethod(HostConfiguration hostConfiguration, + public int executeMethod(HostConfiguration hostconfig, final HttpMethod method, final HttpState state) throws IOException, HttpException { @@ -375,19 +375,20 @@ if (method == null) { throw new IllegalArgumentException("HttpMethod parameter may not be null"); } - HostConfiguration defaulthostconfig = getHostConfiguration(); - if (hostConfiguration == null || hostConfiguration == defaulthostconfig) { + URI uri = method.getURI(); + HostConfiguration defhostconfig = getHostConfiguration(); + if (hostconfig == null || hostconfig == defhostconfig || uri.isAbsoluteURI()) { // make a deep copy of the host defaults - hostConfiguration = new HostConfiguration(defaulthostconfig); - URI uri = method.getURI(); + hostconfig = new HostConfiguration(defhostconfig); + // If absolute request URI is given, override the host config if (uri.isAbsoluteURI()) { - hostConfiguration.setHost(uri); + hostconfig.setHost(uri); } } HttpMethodDirector methodDirector = new HttpMethodDirector( this.httpConnectionManager, - hostConfiguration, + hostconfig, this.params, (state == null ? getState() : state)); methodDirector.executeMethod(method);