With 5.2, we have been using code such as the following to register custom
socket factories to support proxying:
if (proxyProtocolHeader != null) { RegistryBuilder<ConnectionSocketFactory>
registryBuilder = RegistryBuilder.create(); registryBuilder.register("http",
new ProxyProtocolSocketFactory(proxyProtocolHeader,
(InetSocketAddress)proxy.address())); Registry<ConnectionSocketFactory>
registry = registryBuilder.build(); HttpClientConnectionManager ccm = new
BasicHttpClientConnectionManager(registry, ...);
clientBuilder.setConnectionManager(ccm);} where ProxyProtocolSocketFactory
would override its connectSocket method as follows, to connect to the proxy and
write the proxy protocol header:
static class ProxyProtocolSocketFactory extends PlainConnectionSocketFactory {
[...]
@Override public Socket connectSocket(TimeValue connectTimeout, Socket
socket, HttpHost host, InetSocketAddress remoteAddress,
InetSocketAddress localAddress, HttpContext context) throws IOException
{ remoteAddress = proxyAddress != null ? proxyAddress : remoteAddress;
Socket sock = super.connectSocket(connectTimeout, socket, host,
remoteAddress, localAddress, context);
writeProxyProtocolHeader(proxyProtocolHeader, sock); return sock; }}
This no longer works after upgrading to 5.4.1, because our
ProxyProtocolSocketFactory is no longer being called back at its connectSocket
method.
I believe this is due to this change:
https://github.com/apache/httpcomponents-client/commit/851c8df9fff995f8b09c2fef09b5a2ad0dc4185e#diff-c8d113aa21d5fe2678c4c36f731cda6ed01d172d7e47e4d9fc527a5d4a921077R243.
Could you please suggest how we should change our code to make it work again?
Thank you!