diff --git a/src/Confluent.SchemaRegistry/Rest/RestService.cs b/src/Confluent.SchemaRegistry/Rest/RestService.cs index ccee8662d..824b07c3d 100644 --- a/src/Confluent.SchemaRegistry/Rest/RestService.cs +++ b/src/Confluent.SchemaRegistry/Rest/RestService.cs @@ -57,26 +57,14 @@ internal class RestService : IRestService /// /// Initializes a new instance of the RestService class. /// - public RestService(string schemaRegistryUrl, int timeoutMs, IAuthenticationHeaderValueProvider authenticationHeaderValueProvider, List certificates, bool enableSslCertificateVerification) + public RestService(string schemaRegistryUrl, int timeoutMs, IAuthenticationHeaderValueProvider authenticationHeaderValueProvider, List certificates, bool enableSslCertificateVerification) { this.authenticationHeaderValueProvider = authenticationHeaderValueProvider; this.clients = schemaRegistryUrl .Split(',') - .Select(SanitizeUri)// need http or https - use http if not present. - .Select(uri => - { - HttpClient client; -                    if (certificates.Count > 0) -                    { -                        client = new HttpClient(CreateHandler(certificates, enableSslCertificateVerification)) { BaseAddress = new Uri(uri, UriKind.Absolute), Timeout = TimeSpan.FromMilliseconds(timeoutMs) }; -                    } -                    else -                    { -                        client = new HttpClient() { BaseAddress = new Uri(uri, UriKind.Absolute), Timeout = TimeSpan.FromMilliseconds(timeoutMs) }; -                    } - return client; - }) + .Select(SanitizeUri) // need http or https - use http if not present. + .Select(uri => new HttpClient(CreateHandler(certificates, enableSslCertificateVerification)) { BaseAddress = new Uri(uri, UriKind.Absolute), Timeout = TimeSpan.FromMilliseconds(timeoutMs) }) .ToList(); } @@ -86,18 +74,22 @@ private static string SanitizeUri(string uri) return $"{sanitized.TrimEnd('/')}/"; } - private static HttpClientHandler CreateHandler(List certificates, bool enableSslCertificateVerification) + private static HttpClientHandler CreateHandler(List certificates, bool enableSslCertificateVerification) { -     var handler = new HttpClientHandler(); - handler.ClientCertificateOptions = ClientCertificateOption.Manual; + var handler = new HttpClientHandler(); if (!enableSslCertificateVerification) { handler.ServerCertificateCustomValidationCallback = (httpRequestMessage, cert, certChain, policyErrors) => { return true; }; } -     certificates.ForEach(c => handler.ClientCertificates.Add(c)); -     return handler; + if (certificates.Count > 0) + { + handler.ClientCertificateOptions = ClientCertificateOption.Manual; + certificates.ForEach(c => handler.ClientCertificates.Add(c)); + } + + return handler; } private RegisteredSchema SanitizeRegisteredSchema(RegisteredSchema schema)