Apache HttpAsyncClient 5 SOCKS Proxy Settings with IOReactorConfig
Set the reactor proxy address before starting HttpAsyncClient 5, rather than applying the classic client's socket configuration.
import java.net.InetSocketAddress;
import org.apache.hc.core5.reactor.IOReactorConfig;
import org.apache.hc.client5.http.impl.async.HttpAsyncClients;
var reactor = IOReactorConfig.custom()
.setSocksProxyAddress(new InetSocketAddress("proxy.example", 1080))
.build();
var client = HttpAsyncClients.custom()
.setIOReactorConfig(reactor)
.build();
client.start();Send the intended asynchronous requests through this client, retaining their actual destination URIs. Keep the client alive for the workload and close it afterward. For permitted public-target requests, the SOCKS proxy list supplies host and port candidates; match the SOCKS version supported by the reactor.
The reactor controls this asynchronous socket path. An HTTP HttpHost proxy route or classic connection-manager SocketConfig is another interface.
For supported SOCKS username/password authentication, set setSocksProxyUsername and setSocksProxyPassword on the reactor builder too. Finish configuration before start, rather than changing shared settings while requests run.