Oleg, thank you for your suggestion! I'm afraid implementing our own 
HttpClientConnectionOperator is going to result in a lot of code duplication. 
We'd essentially have to copy the It also seems like a significant breaking 
change for a minor release upgrade. It looks like by default, only custom 
socket factories that are instances of LayeredConnectionSocketFactory are now 
being considered, which covers one of our proxy socket factories which extends 
SSLConnectionSocketFactory, but not the one other that extends 
PlainConnectionSocketFactory. It also looks like only TLS upgrade functionalty 
can now be customized. In any case, we're a bit blocked right now ...

    On Tuesday, January 7, 2025 at 11:30:50 AM PST, Oleg Kalnichevski 
<ol...@apache.org> wrote:  
 
 On Tue, 2025-01-07 at 02:08 +0000, jan luehe wrote:
>  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!

If you want a complete control over the process of connection
initialization implement a custom HttpClientConnectionOperator

https://github.com/apache/httpcomponents-client/blob/master/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultHttpClientConnectionOperator.java

Oleg

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscr...@hc.apache.org
For additional commands, e-mail: httpclient-users-h...@hc.apache.org

  

Reply via email to