HTTPCLIENT-2242: RoutingSupport fails to copy InetAddress when normalizing HttpHost
This commit is contained in:
parent
fe1e095ef9
commit
16b2cf467d
|
@ -73,7 +73,7 @@ public final class RoutingSupport {
|
||||||
if (host.getPort() < 0) {
|
if (host.getPort() < 0) {
|
||||||
final int port = (schemePortResolver != null ? schemePortResolver: DefaultSchemePortResolver.INSTANCE).resolve(host);
|
final int port = (schemePortResolver != null ? schemePortResolver: DefaultSchemePortResolver.INSTANCE).resolve(host);
|
||||||
if (port > 0) {
|
if (port > 0) {
|
||||||
return new HttpHost(host.getSchemeName(), host.getHostName(), port);
|
return new HttpHost(host.getSchemeName(), host.getAddress(), host.getHostName(), port);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return host;
|
return host;
|
||||||
|
|
|
@ -29,8 +29,10 @@ package org.apache.hc.client5.http.impl.routing;
|
||||||
|
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
|
|
||||||
|
import java.net.InetAddress;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
|
||||||
|
import org.apache.hc.client5.http.impl.DefaultSchemePortResolver;
|
||||||
import org.apache.hc.client5.http.routing.RoutingSupport;
|
import org.apache.hc.client5.http.routing.RoutingSupport;
|
||||||
import org.apache.hc.core5.http.HttpHost;
|
import org.apache.hc.core5.http.HttpHost;
|
||||||
import org.apache.hc.core5.http.HttpRequest;
|
import org.apache.hc.core5.http.HttpRequest;
|
||||||
|
@ -62,4 +64,24 @@ public class TestRoutingSupport {
|
||||||
RoutingSupport.determineHost(request1));
|
RoutingSupport.determineHost(request1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNormalizeHost() throws Exception {
|
||||||
|
Assertions.assertEquals(new HttpHost("http", "somehost", 80),
|
||||||
|
RoutingSupport.normalize(
|
||||||
|
new HttpHost("http", "somehost", -1),
|
||||||
|
DefaultSchemePortResolver.INSTANCE));
|
||||||
|
Assertions.assertEquals(new HttpHost("https", "somehost", 443),
|
||||||
|
RoutingSupport.normalize(
|
||||||
|
new HttpHost("https", "somehost", -1),
|
||||||
|
DefaultSchemePortResolver.INSTANCE));
|
||||||
|
Assertions.assertEquals(new HttpHost("http", InetAddress.getLocalHost(), "localhost", 80),
|
||||||
|
RoutingSupport.normalize(
|
||||||
|
new HttpHost("http", InetAddress.getLocalHost(), "localhost", -1),
|
||||||
|
DefaultSchemePortResolver.INSTANCE));
|
||||||
|
Assertions.assertEquals(new HttpHost("http", "somehost", 8080),
|
||||||
|
RoutingSupport.normalize(
|
||||||
|
new HttpHost("http", "somehost", 8080),
|
||||||
|
DefaultSchemePortResolver.INSTANCE));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue