-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Description
I would like to use SocketsHttpHandler instead of HttpClientHandler, because of the additional timeout options. In my current implementation I use HttpClientHandler.ServerCertificateCustomValidationCallback to implement custom SSL certificate validation. Inside the callback I use HttpRequestMessage.RequestUri.Host to see if the user has configured a trusted certificate for the specified host. If the certificate is not trusted, then I add the certificate to HttpRequestMessage.Properties, so that the requester/caller can show the certificate to the user. When I try to re-implement this using SocketsHttpHandler.SslOptions.RemoteCertificateValidationCallback, then I get an SslStream instead of a HttpResponseMessage. As a result I do not know for which host I am verifying the certificate and I cannot add the certificate to the request properties.
As a workaround I use reflection to get HttpClientHandler._socketsHttpHandler, so that I can configure the timeout options of SocketsHttpHandler, while still using HttpClientHandler. Of course I would prefer not having to resort to using reflection and exploiting implementation details.
Another way to allow this is to expose System.Net.Http.ConnectHelper.CertificateCallbackMapper, which is what HttpClientHandler.ServerCertificateCustomValidationCallback uses internally.