[ 
https://issues.apache.org/jira/browse/HTTPCLIENT-2242?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Oleg Kalnichevski resolved HTTPCLIENT-2242.
-------------------------------------------
    Fix Version/s: 5.1.4
                   5.2-beta2
       Resolution: Fixed

> 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
>            Priority: Minor
>             Fix For: 5.1.4, 5.2-beta2
>
>
> 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: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to