private static HttpClientHandler CreateClientHandler(ClusterContext context, ILogger <CouchbaseHttpClient> logger) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (logger == null) { throw new ArgumentNullException(nameof(logger)); } HttpClientHandler handler; //for x509 cert authentication if (context.ClusterOptions.X509CertificateFactory != null) { handler = new NonAuthenticatingHttpClientHandler { ClientCertificateOptions = ClientCertificateOption.Manual, SslProtocols = SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12 }; handler.ClientCertificates.AddRange(context.ClusterOptions.X509CertificateFactory.GetCertificates()); } else { handler = new AuthenticatingHttpClientHandler(context); } try { handler.CheckCertificateRevocationList = context.ClusterOptions.EnableCertificateRevocation; handler.ServerCertificateCustomValidationCallback = CreateCertificateValidator(context.ClusterOptions); } catch (PlatformNotSupportedException) { logger.LogDebug("Cannot set ServerCertificateCustomValidationCallback, not supported on this platform"); } catch (NotImplementedException) { logger.LogDebug("Cannot set ServerCertificateCustomValidationCallback, not implemented on this platform"); } try { if (context.ClusterOptions.MaxHttpConnections > 0) { //0 means the WinHttpHandler default size of Int.MaxSize is used handler.MaxConnectionsPerServer = context.ClusterOptions.MaxHttpConnections; } } catch (PlatformNotSupportedException e) { logger.LogDebug("Cannot set MaxConnectionsPerServer, not supported on this platform", e); } return(handler); }
private static HttpClientHandler CreateClientHandler(string username, string password, ClientConfiguration config) #endif { #if NET452 WebRequestHandler handler; #else HttpClientHandler handler; #endif //for x509 cert authentication if (config != null && config.EnableCertificateAuthentication) { handler = new NonAuthenticatingHttpClientHandler { ClientCertificateOptions = ClientCertificateOption.Manual }; #if NETSTANDARD handler.SslProtocols = SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12; handler.ClientCertificates.AddRange(config.CertificateFactory()); #endif } else { handler = new AuthenticatingHttpClientHandler(username, password); } #if NET452 // ReSharper disable once PossibleNullReferenceException handler.ServerCertificateValidationCallback = config.HttpServerCertificateValidationCallback ?? OnCertificateValidation; #else try { handler.CheckCertificateRevocationList = config.EnableCertificateRevocation; handler.ServerCertificateCustomValidationCallback = config?.HttpServerCertificateValidationCallback ?? OnCertificateValidation; } catch (NotImplementedException) { Log.Debug("Cannot set ServerCertificateCustomValidationCallback, not supported on this platform"); } if (config != null) { try { handler.MaxConnectionsPerServer = config.DefaultConnectionLimit; } catch (PlatformNotSupportedException e) { Log.Debug("Cannot set MaxConnectionsPerServer, not supported on this platform", e); } } #endif return(handler); }
private static HttpClientHandler CreateClientHandler(ClusterContext context) { HttpClientHandler handler; //for x509 cert authentication if (context.ClusterOptions.EnableCertificateAuthentication) { handler = new NonAuthenticatingHttpClientHandler { ClientCertificateOptions = ClientCertificateOption.Manual, SslProtocols = SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12 }; //handler.ClientCertificates.AddRange(config.CertificateFactory()); //TODO } else { handler = new AuthenticatingHttpClientHandler(context); } try { handler.CheckCertificateRevocationList = context.ClusterOptions.EnableCertificateRevocation; //handler.ServerCertificateCustomValidationCallback = config?.HttpServerCertificateValidationCallback ?? // OnCertificateValidation; } catch (NotImplementedException) { Logger.LogDebug("Cannot set ServerCertificateCustomValidationCallback, not supported on this platform"); } try { if (context.ClusterOptions.MaxHttpConnection > 0) { handler.MaxConnectionsPerServer = context.ClusterOptions.MaxHttpConnection; } } catch (PlatformNotSupportedException e) { Logger.LogDebug("Cannot set MaxConnectionsPerServer, not supported on this platform", e); } return(handler); }
private static HttpClientHandler CreateClientHandler(string username, string password, Couchbase.Configuration clientConfig) { HttpClientHandler handler; //for x509 cert authentication if (clientConfig != null && clientConfig.EnableCertificateAuthentication) { handler = new NonAuthenticatingHttpClientHandler { ClientCertificateOptions = ClientCertificateOption.Manual, SslProtocols = SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12 }; //handler.ClientCertificates.AddRange(config.CertificateFactory()); //TODO } else { handler = new AuthenticatingHttpClientHandler(username, password); } try { handler.CheckCertificateRevocationList = clientConfig.EnableCertificateRevocation; //handler.ServerCertificateCustomValidationCallback = config?.HttpServerCertificateValidationCallback ?? // OnCertificateValidation; } catch (NotImplementedException) { //Log.Debug("Cannot set ServerCertificateCustomValidationCallback, not supported on this platform"); } if (clientConfig != null) { try { handler.MaxConnectionsPerServer = clientConfig.MaxQueryConnectionsPerServer; } catch (PlatformNotSupportedException e) { // Log.Debug("Cannot set MaxConnectionsPerServer, not supported on this platform", e); } } return(handler); }