Second fix for HTTPCLIENT-1296. Include Oleg's suggestions as to a better way to obtain a port from the non-existent target.
git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1431285 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a7984199d7
commit
4a9f0a6ebb
|
@ -380,6 +380,15 @@ public class DefaultRequestDirector implements RequestDirector {
|
||||||
|
|
||||||
virtualHost = (HttpHost) origWrapper.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) {
|
||||||
|
HttpHost host = (target != null) ? target : origRoute.getTargetHost();
|
||||||
|
int port = host.getPort();
|
||||||
|
if (port != -1){
|
||||||
|
virtualHost = new HttpHost(virtualHost.getHostName(), port, virtualHost.getSchemeName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
RoutedRequest roureq = new RoutedRequest(origWrapper, origRoute);
|
RoutedRequest roureq = new RoutedRequest(origWrapper, origRoute);
|
||||||
|
|
||||||
boolean reuse = false;
|
boolean reuse = false;
|
||||||
|
@ -449,27 +458,19 @@ public class DefaultRequestDirector implements RequestDirector {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get target. Even if there's virtual host, we may need the target to set the port.
|
// Get target. Even if there's virtual host, we may need the target to set the port.
|
||||||
URI requestURI = wrapper.getURI();
|
if (virtualHost != null) {
|
||||||
if (requestURI.isAbsolute()) {
|
target = virtualHost;
|
||||||
target = new HttpHost(
|
} else {
|
||||||
requestURI.getHost(), requestURI.getPort(), requestURI.getScheme());
|
URI requestURI = wrapper.getURI();
|
||||||
|
if (requestURI.isAbsolute()) {
|
||||||
|
target = new HttpHost(
|
||||||
|
requestURI.getHost(), requestURI.getPort(), requestURI.getScheme());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (target == null) {
|
if (target == null) {
|
||||||
target = route.getTargetHost();
|
target = route.getTargetHost();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Override the target if the virtual host is present. But make sure the port is right.
|
|
||||||
if (virtualHost != null) {
|
|
||||||
// HTTPCLIENT-1092 - add the port if necessary
|
|
||||||
if (virtualHost.getPort() == -1 && target != null) {
|
|
||||||
int port = target.getPort();
|
|
||||||
if (port != -1) {
|
|
||||||
virtualHost = new HttpHost(virtualHost.getHostName(), port, virtualHost.getSchemeName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
target = virtualHost;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reset headers on the request wrapper
|
// Reset headers on the request wrapper
|
||||||
wrapper.resetHeaders();
|
wrapper.resetHeaders();
|
||||||
// Re-write request URI if needed
|
// Re-write request URI if needed
|
||||||
|
|
Loading…
Reference in New Issue