@@ -65,25 +65,9 @@ public RestService(string schemaRegistryUrl, int timeoutMs,
65
65
this . clients = schemaRegistryUrl
66
66
. Split ( ',' )
67
67
. Select ( SanitizeUri ) // need http or https - use http if not present.
68
- . Select ( uri =>
68
+ . Select ( uri => new HttpClient ( CreateHandler ( certificates , enableSslCertificateVerification , sslCaCertificate ) )
69
69
{
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 )
87
71
} )
88
72
. ToList ( ) ;
89
73
}
@@ -98,9 +82,6 @@ private static HttpClientHandler CreateHandler(List<X509Certificate2> certificat
98
82
bool enableSslCertificateVerification , X509Certificate2 sslCaCertificate )
99
83
{
100
84
var handler = new HttpClientHandler ( ) ;
101
- handler . ClientCertificateOptions = ClientCertificateOption . Manual ;
102
-
103
- certificates . ForEach ( c => handler . ClientCertificates . Add ( c ) ) ;
104
85
105
86
if ( ! enableSslCertificateVerification )
106
87
{
@@ -115,7 +96,6 @@ private static HttpClientHandler CreateHandler(List<X509Certificate2> certificat
115
96
return true ;
116
97
}
117
98
118
-
119
99
//The second element of the chain should be the issuer of the certificate
120
100
if ( chain . ChainElements . Count < 2 )
121
101
{
@@ -141,7 +121,13 @@ private static HttpClientHandler CreateHandler(List<X509Certificate2> certificat
141
121
return true ;
142
122
} ;
143
123
}
144
-
124
+
125
+ if ( certificates . Count > 0 )
126
+ {
127
+ handler . ClientCertificateOptions = ClientCertificateOption . Manual ;
128
+ certificates . ForEach ( c => handler . ClientCertificates . Add ( c ) ) ;
129
+ }
130
+
145
131
return handler ;
146
132
}
147
133
0 commit comments