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 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); }