private HttpClientHandler(bool useSocketsHttpHandler) // used by parameterless ctor and as hook for testing
        {
            if (useSocketsHttpHandler)
            {
                _socketsHttpHandler      = new SocketsHttpHandler();
                _diagnosticsHandler      = new DiagnosticsHandler(_socketsHttpHandler);
                ClientCertificateOptions = ClientCertificateOption.Manual;
            }
            else
            {
                _winHttpHandler     = new WinHttpHandler();
                _diagnosticsHandler = new DiagnosticsHandler(_winHttpHandler);

                // Adjust defaults to match current .NET Desktop HttpClientHandler (based on HWR stack).
                AllowAutoRedirect      = true;
                AutomaticDecompression = HttpHandlerDefaults.DefaultAutomaticDecompression;
                UseProxy        = true;
                UseCookies      = true;
                CookieContainer = new CookieContainer();
                _winHttpHandler.DefaultProxyCredentials = null;
                _winHttpHandler.ServerCredentials       = null;

                // The existing .NET Desktop HttpClientHandler based on the HWR stack uses only WinINet registry
                // settings for the proxy.  This also includes supporting the "Automatic Detect a proxy" using
                // WPAD protocol and PAC file. So, for app-compat, we will do the same for the default proxy setting.
                _winHttpHandler.WindowsProxyUsePolicy = WindowsProxyUsePolicy.UseWinInetProxy;
                _winHttpHandler.Proxy = null;

                // Since the granular WinHttpHandler timeout properties are not exposed via the HttpClientHandler API,
                // we need to set them to infinite and allow the HttpClient.Timeout property to have precedence.
                _winHttpHandler.ReceiveHeadersTimeout = Timeout.InfiniteTimeSpan;
                _winHttpHandler.ReceiveDataTimeout    = Timeout.InfiniteTimeSpan;
                _winHttpHandler.SendTimeout           = Timeout.InfiniteTimeSpan;
            }
        }
Exemplo n.º 2
0
 static ClientFactory()
 {
     Cookies         = new CookieContainer();
     _socketsHandler = new SysHttp.SocketsHttpHandler
     {
         CookieContainer             = Cookies,
         MaxConnectionsPerServer     = 20,
         PooledConnectionLifetime    = TimeSpan.FromMilliseconds(100),
         PooledConnectionIdleTimeout = TimeSpan.FromMilliseconds(100)
     };
     Client = new SysHttp.HttpClient(_socketsHandler);
 }
Exemplo n.º 3
0
 internal HttpClientHandler(IMonoHttpClientHandler monoHandler)
 {
     if (monoHandler != null)
     {
         _monoHandler = monoHandler;
     }
     else
     {
         _socketsHttpHandler      = new SocketsHttpHandler();
         ClientCertificateOptions = ClientCertificateOption.Manual;
     }
 }
Exemplo n.º 4
0
 private HttpClientHandler(bool useSocketsHttpHandler) // used by parameterless ctor and as hook for testing
 {
     if (useSocketsHttpHandler)
     {
         _socketsHttpHandler = new SocketsHttpHandler();
         _diagnosticsHandler = new DiagnosticsHandler(_socketsHttpHandler);
     }
     else
     {
         _curlHandler        = new CurlHandler();
         _diagnosticsHandler = new DiagnosticsHandler(_curlHandler);
     }
 }
Exemplo n.º 5
0
 static ClientFactory()
 {
     Cookies         = new CookieContainer();
     _socketsHandler = new SysHttp.SocketsHttpHandler
     {
         CookieContainer             = Cookies,
         MaxConnectionsPerServer     = 20,
         PooledConnectionLifetime    = TimeSpan.FromMilliseconds(100),
         PooledConnectionIdleTimeout = TimeSpan.FromMilliseconds(100),
     };
     Utils.Log($"Configuring with SSL {_socketsHandler.SslOptions.EnabledSslProtocols}");
     Client = new SysHttp.HttpClient(_socketsHandler);
 }
Exemplo n.º 6
0
        static ClientFactory()
        {
            Cookies         = new CookieContainer();
            _socketsHandler = new SysHttp.SocketsHttpHandler
            {
                CookieContainer             = Cookies,
                MaxConnectionsPerServer     = 20,
                PooledConnectionLifetime    = TimeSpan.FromMilliseconds(100),
                PooledConnectionIdleTimeout = TimeSpan.FromMilliseconds(100),
                AutomaticDecompression      = DecompressionMethods.All,
            };

            ServicePointManager.ServerCertificateValidationCallback +=
                (sender, certificate, chain, errors) =>
            {
                if (Consts.UseNetworkWorkaroundMode)
                {
                    return(true);
                }
                return(errors == SslPolicyErrors.None);
            };
            Client = new SysHttp.HttpClient(_socketsHandler);
            Client.DefaultRequestHeaders.Add("User-Agent", Consts.UserAgent);
        }
Exemplo n.º 7
0
 public HttpClientHandler()
 {
     _socketsHttpHandler      = new SocketsHttpHandler();
     _diagnosticsHandler      = new DiagnosticsHandler(_socketsHttpHandler);
     ClientCertificateOptions = ClientCertificateOption.Manual;
 }