コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }