arturobernalg commented on PR #692:
URL: 
https://github.com/apache/httpcomponents-client/pull/692#issuecomment-3136965295

   > > 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();
   > >                     }
   > >                 };
   > > ```
   > 
   > @winfriedgerlach 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.
   
   @winfriedgerlach, to build on that IMO, exposing logging internals like 
`LoggingInputStream` could introduce unintended side effects in performance or 
even security, as users might override them in ways that disrupt stream 
handling or leak data.


-- 
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

Reply via email to