You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "Lubos Kolarik (Jira)" <ji...@apache.org> on 2022/10/25 10:15:00 UTC
[jira] [Created] (HTTPCLIENT-2242) HttpHost.address not used when httpHost is specified without port
Lubos Kolarik created HTTPCLIENT-2242:
-----------------------------------------
Summary: HttpHost.address not used when httpHost is specified without port
Key: HTTPCLIENT-2242
URL: https://issues.apache.org/jira/browse/HTTPCLIENT-2242
Project: HttpComponents HttpClient
Issue Type: Bug
Components: HttpClient (async)
Affects Versions: 5.1.3
Reporter: Lubos Kolarik
I am passing {{HttpHost}} instance with predefined IP to {{execute}} method of CloseableAsyncHttpClient.
This works and the dns resolver is not used for the request. But it only works if port is specified in the HttpHost. When I specify -1 as a port, then default is correctly used, but IP address from HttpHost is lost during request preprocessing -> DnsResolver is called and IP is resolved again.
I think the problem is within the {{org.apache.hc.client5.http.routing.RoutingSupport#normalize}} method. Here the port is set to default, according to scheme, but the {{address}} field is not transferred to the newly created {{HttpHost}} instance
Simple testing example:
Here when port is set to -1, dns resolving happens and custom dns resolver is called - NOK
When port is set to be > 0, dns resolving is correctly skipped and predefined localhost address is used - OK
{code:java}
public static void main(String[] args)
throws UnknownHostException, ExecutionException, InterruptedException {
PoolingAsyncClientConnectionManager connectionManager =
PoolingAsyncClientConnectionManagerBuilder.create()
.setDnsResolver(
new DnsResolver() {
@Override
public InetAddress[] resolve(String host) throws UnknownHostException {
throw new UnknownHostException("Trying to resolve IP address");
}
@Override
public String resolveCanonicalHostname(String host) throws UnknownHostException {
throw new UnknownHostException("Trying to resolve IP address");
}
})
.build();
CloseableHttpAsyncClient client =
HttpAsyncClients.custom().setConnectionManager(connectionManager).build();
try {
client.start();
SimpleHttpRequest request = SimpleHttpRequest.create("GET", "/");
HttpHost httpHost = new HttpHost("https", InetAddress.getLocalHost(), "google.com", -1);
HttpClientContext context = HttpClientContext.create();
SimpleResponseConsumer responseConsumer = SimpleResponseConsumer.create();
client
.execute(
httpHost,
SimpleRequestProducer.create(request),
responseConsumer,
null,
context,
null)
.get();
} finally {
client.close(CloseMode.GRACEFUL);
}
}
{code}
Thanks for checking
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org