arturobernalg commented on PR #692: URL: https://github.com/apache/httpcomponents-client/pull/692#issuecomment-3136876685
> Hi @arturobernalg, I am already using a custom connection factory to create my "instrumented connections". But that was not the question that I wanted to answer with this PR: I wanted to make the creation of such "custom connections" easier. > > Take this example: if I principally appreciate the behavior of `DefaultManagedHttpClientConnection` and it was not final, I could easily add stuff to the log when closing a connection. > > ```java > // in ManagedHttpClientConnectionFactory#createConnection: > final var connection = new DefaultManagedHttpClientConnection(id) { > @Override > public void close() throws IOException { > var certificate = (X509Certificate) getSSLSession().getPeerCertificates()[0]; > var dn = certificate.getSubjectX500Principal().getName(); > LOG.info("Closing connection {} with DN: {}", id, dn); > super.close(); > } > }; > ``` Use the `HttpConnectionFactory` SPI with an anonymous decorator around `DefaultManagedHttpClientConnection` to override `close()` for your logging. That way you don’t expose internals and keep the API sealed while getting the extension you need. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org For additional commands, e-mail: dev-h...@hc.apache.org