public void Test_AllowPipelining_Is_False_When_Username_And_Password_Is_Set()
        {
#if NET452
            var handler = new AuthenticatingHttpClientHandler("username", "password");
            Assert.IsFalse(handler.AllowPipelining);
#endif
        }
Exemple #2
0
        private static AuthenticatingHttpClientHandler CreateClientHandler(string username, string password, ClientConfiguration config)
        {
            var handler = new AuthenticatingHttpClientHandler(username, password);

#if NET45
            handler.ServerCertificateValidationCallback = OnCertificateValidation;
#else
            try
            {
                handler.ServerCertificateCustomValidationCallback = 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);
        }
        public void Test_AllowPipelining_Is_False()
        {
#if NET452
            var handler = new AuthenticatingHttpClientHandler();
            Assert.IsFalse(handler.AllowPipelining);
#endif
        }
Exemple #4
0
        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);
        }
        public HttpClient CreateHttpClient()
        {
            var url = new Uri(new Uri(Options.Url, UriKind.Absolute), "/api/");

            var handler = new AuthenticatingHttpClientHandler(Options.Authenticator);

            Options.Configurator.Configure(handler);

            var httpClient = new HttpClient(handler, false)
            {
                BaseAddress = url
            };

            Options.Configurator.Configure(httpClient);

            return(httpClient);
        }
Exemple #6
0
        public HttpClient CreateHttpClient()
        {
            var url = new Uri(serviceUrl, "/api/");

            var handler = new AuthenticatingHttpClientHandler(authenticator);

            httpConfigurator.Configure(handler);

            var httpClient = new HttpClient(handler, false)
            {
                BaseAddress = url
            };

            httpConfigurator.Configure(httpClient);

            return(httpClient);
        }
Exemple #7
0
        private static AuthenticatingHttpClientHandler CreateClientHandler(string username, string password, ClientConfiguration config)
        {
            var handler = new AuthenticatingHttpClientHandler(username, password);

            //for x509 cert authentication
            if (config != null && config.EnableCertificateAuthentication)
            {
                handler.ClientCertificateOptions = ClientCertificateOption.Manual;
                handler.ClientCertificates.AddRange(config.CertificateFactory());
            }

#if NET45
            // ReSharper disable once PossibleNullReferenceException
            handler.ServerCertificateValidationCallback = config.HttpServerCertificateValidationCallback ??
                                                          OnCertificateValidation;
#else
            try
            {
                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);
        }
Exemple #8
0
 internal CouchbaseHttpClient(AuthenticatingHttpClientHandler handler)
     : base(handler)
 {
     DefaultRequestHeaders.Add(UserAgentHeaderName, ClientIdentifier.GetClientDescription());
 }
 internal CouchbaseHttpClient(AuthenticatingHttpClientHandler handler)
     : base(handler)
 {
 }