ClientPNames.VIRTUAL_HOST has no effect if set at the client level

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1296612 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2012-03-03 12:28:59 +00:00
parent b90f31138c
commit a32899e446
2 changed files with 27 additions and 2 deletions

View File

@ -410,8 +410,7 @@ public class DefaultRequestDirector implements RequestDirector {
origWrapper.setParams(params);
HttpRoute origRoute = determineRoute(target, origWrapper, context);
virtualHost = (HttpHost) orig.getParams().getParameter(
ClientPNames.VIRTUAL_HOST);
virtualHost = (HttpHost) origWrapper.getParams().getParameter(ClientPNames.VIRTUAL_HOST);
// HTTPCLIENT-1092 - add the port if necessary
if (virtualHost != null && virtualHost.getPort() == -1) {

View File

@ -184,6 +184,32 @@ public class TestDefaultClientRequestDirector extends BasicServerTestBase {
Assert.assertEquals(virtHost+":"+virtPort,headers[0].getValue());
}
@Test
public void testClientLevelVirtualHostHeader() throws Exception {
int port = this.localServer.getServiceAddress().getPort();
this.localServer.register("*", new SimpleService());
HttpContext context = new BasicHttpContext();
String s = "http://localhost:" + port;
HttpGet httpget = new HttpGet(s);
String virtHost = "virtual";
this.httpclient.getParams().setParameter(ClientPNames.VIRTUAL_HOST, new HttpHost(virtHost, port));
HttpResponse response = this.httpclient.execute(getServerHttp(), httpget, context);
EntityUtils.consume(response.getEntity());
HttpRequest reqWrapper = (HttpRequest) context.getAttribute(
ExecutionContext.HTTP_REQUEST);
Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
// Check that Host header is generated as expected
Header[] headers = reqWrapper.getHeaders("host");
Assert.assertNotNull(headers);
Assert.assertEquals(1, headers.length);
Assert.assertEquals(virtHost+":"+port,headers[0].getValue());
}
@Test
public void testDefaultHostAtRequestLevel() throws Exception {
int port = this.localServer.getServiceAddress().getPort();