@@ -65,25 +65,9 @@ public RestService(string schemaRegistryUrl, int timeoutMs,
6565 this . clients = schemaRegistryUrl
6666 . Split ( ',' )
6767 . Select ( SanitizeUri ) // need http or https - use http if not present.
68- . Select ( uri =>
68+ . Select ( uri => new HttpClient ( CreateHandler ( certificates , enableSslCertificateVerification , sslCaCertificate ) )
6969 {
70- HttpClient client ;
71- if ( certificates . Count > 0 )
72- {
73- client = new HttpClient ( CreateHandler ( certificates , enableSslCertificateVerification , sslCaCertificate ) )
74- {
75- BaseAddress = new Uri ( uri , UriKind . Absolute ) , Timeout = TimeSpan . FromMilliseconds ( timeoutMs )
76- } ;
77- }
78- else
79- {
80- client = new HttpClient ( )
81- {
82- BaseAddress = new Uri ( uri , UriKind . Absolute ) , Timeout = TimeSpan . FromMilliseconds ( timeoutMs )
83- } ;
84- }
85-
86- return client ;
70+ BaseAddress = new Uri ( uri , UriKind . Absolute ) , Timeout = TimeSpan . FromMilliseconds ( timeoutMs )
8771 } )
8872 . ToList ( ) ;
8973 }
@@ -98,9 +82,6 @@ private static HttpClientHandler CreateHandler(List<X509Certificate2> certificat
9882 bool enableSslCertificateVerification , X509Certificate2 sslCaCertificate )
9983 {
10084 var handler = new HttpClientHandler ( ) ;
101- handler . ClientCertificateOptions = ClientCertificateOption . Manual ;
102-
103- certificates . ForEach ( c => handler . ClientCertificates . Add ( c ) ) ;
10485
10586 if ( ! enableSslCertificateVerification )
10687 {
@@ -115,7 +96,6 @@ private static HttpClientHandler CreateHandler(List<X509Certificate2> certificat
11596 return true ;
11697 }
11798
118-
11999 //The second element of the chain should be the issuer of the certificate
120100 if ( chain . ChainElements . Count < 2 )
121101 {
@@ -141,7 +121,13 @@ private static HttpClientHandler CreateHandler(List<X509Certificate2> certificat
141121 return true ;
142122 } ;
143123 }
144-
124+
125+ if ( certificates . Count > 0 )
126+ {
127+ handler . ClientCertificateOptions = ClientCertificateOption . Manual ;
128+ certificates . ForEach ( c => handler . ClientCertificates . Add ( c ) ) ;
129+ }
130+
145131 return handler ;
146132 }
147133
0 commit comments