ok2c/httpclient-migration-guide

CloseableHttpAsyncClient request via a proxy

brr53 opened this issue · 3 comments

brr53 commented

Hi there.

I noticed that when I send a request with CloseableHttpAsyncClient using Apache HttpClient 5.0, it runs into an exception “No tunnel unless connected” when requesting via HTTPS. However with HTTP, everything works as normal.

Code works perfectly when proxies are not used.

` try{
sslContext = SSLContexts.custom()
.setProvider(Conscrypt.newProvider())
.build();
}catch (Exception e){
e.printStackTrace();
}

    final PoolingAsyncClientConnectionManager cm = PoolingAsyncClientConnectionManagerBuilder.create()
            .setTlsStrategy(new ConscryptClientTlsStrategy(sslContext))
            .build();

BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
if (proxy.isAuth()) {
credentialsProvider.setCredentials(
new AuthScope(proxy.getIp(), Integer.parseInt(proxy.getPort())),
new UsernamePasswordCredentials(proxy.getUsername(), proxy.getPassword().toCharArray()));
}

HttpHost p = new HttpHost(proxy.getIp(), Integer.parseInt(proxy.getPort()), "http");

asyncClient = HttpAsyncClients.custom()
.setVersionPolicy(HttpVersionPolicy.FORCE_HTTP_1)
.setConnectionManager(cm)
.setUserAgent(Utils.USER_AGENT)
.setDefaultCookieStore(cookieStore)
.setDefaultCredentialsProvider(credentialsProvider)
.setProxy(p)
.build();

asyncClient.start();`

thank you!

ok2c commented

@bayanrasooly Please post the exception with the exact stack trace.

brr53 commented

https://howsmyssl.com/a/check->java.lang.IllegalStateException: No tunnel unless connected java.util.concurrent.ExecutionException: java.lang.IllegalStateException: No tunnel unless connected at org.apache.hc.core5.concurrent.BasicFuture.getResult(BasicFuture.java:72) at org.apache.hc.core5.concurrent.BasicFuture.get(BasicFuture.java:85) at ApacheHttpClient.HttpClient.getSimpleResponse(HttpClient.java:132) at Testing.NetworkTests.getInitialCookie(NetworkTests.java:23) at Testing.NetworkTests.main(NetworkTests.java:32) Caused by: java.lang.IllegalStateException: No tunnel unless connected at org.apache.hc.core5.util.Asserts.check(Asserts.java:38) at org.apache.hc.client5.http.RouteTracker.tunnelTarget(RouteTracker.java:143) at org.apache.hc.client5.http.impl.async.AsyncConnectExec$4.completed(AsyncConnectExec.java:269) at org.apache.hc.client5.http.impl.async.AsyncConnectExec$5.completed(AsyncConnectExec.java:387) at org.apache.hc.client5.http.impl.async.HttpAsyncMainClientExec$1.consumeResponse(HttpAsyncMainClientExec.java:206) at org.apache.hc.core5.http.impl.nio.ClientHttp1StreamHandler.consumeHeader(ClientHttp1StreamHandler.java:254) at org.apache.hc.core5.http.impl.nio.ClientHttp1StreamDuplexer.consumeHeader(ClientHttp1StreamDuplexer.java:351) at org.apache.hc.core5.http.impl.nio.ClientHttp1StreamDuplexer.consumeHeader(ClientHttp1StreamDuplexer.java:80) at org.apache.hc.core5.http.impl.nio.AbstractHttp1StreamDuplexer.onInput(AbstractHttp1StreamDuplexer.java:278) at org.apache.hc.core5.http.impl.nio.AbstractHttp1IOEventHandler.inputReady(AbstractHttp1IOEventHandler.java:64) at org.apache.hc.core5.http.impl.nio.ClientHttp1IOEventHandler.inputReady(ClientHttp1IOEventHandler.java:39) at org.apache.hc.core5.reactor.InternalDataChannel.onIOEvent(InternalDataChannel.java:124) at org.apache.hc.core5.reactor.InternalChannel.handleIOEvent(InternalChannel.java:51) at org.apache.hc.core5.reactor.SingleCoreIOReactor.processEvents(SingleCoreIOReactor.java:179) at org.apache.hc.core5.reactor.SingleCoreIOReactor.doExecute(SingleCoreIOReactor.java:128) at org.apache.hc.core5.reactor.AbstractSingleCoreIOReactor.execute(AbstractSingleCoreIOReactor.java:85) at org.apache.hc.core5.reactor.IOReactorWorker.run(IOReactorWorker.java:44) at java.lang.Thread.run(Thread.java:748)

ok2c commented

@ok2c No idea why your code is hitting this assert. Please raise a JIRA with Apache HttpClient project and provide a fully functional test application or a test case that can be used to reproduce the issue. I will look further once there is a local reproducer.