示例#1
0
 public void TestCheckHttpTimeoutProperty_stringValue()
 {
     Environment.SetEnvironmentVariable(FibSystemProperties.HttpTimeout, "random string");
     try
     {
         FibSystemProperties.CheckHttpTimeoutProperty();
         Assert.Fail();
     }
     catch (FormatException ex)
     {
         Assert.AreEqual("fib.httpTimeout must be an integer: random string", ex.Message);
     }
 }
示例#2
0
            /**
             * The {@code User-Agent} is in the form of {@code fib <version> <type>}. For example: {@code
             * fib 0.9.0 fib-maven-plugin}.
             *
             * @return the {@code User-Agent} header to send. The {@code User-Agent} can be disabled by
             *     setting the system property variable {@code _JIB_DISABLE_USER_AGENT} to any non-empty
             *     string.
             */
            private IEnumerable <ProductInfoHeaderValue> MakeUserAgent()
            {
                if (!FibSystemProperties.IsUserAgentEnabled())
                {
                    yield break;
                }

                yield return(defaultFibUserAgent);

                foreach (var value in additionalUserAgentValues)
                {
                    yield return(value);
                }
            }
示例#3
0
 public Connection(Uri url, bool insecure)
 {
     if (insecure)
     {
         client = insecureClients.GetOrAdd(url, _ => new HttpClient(insecureHandler)
         {
             BaseAddress = url,
             Timeout     = TimeSpan.FromMilliseconds(FibSystemProperties.GetHttpTimeout()),
         });
     }
     else
     {
         client = clients.GetOrAdd(url, _ => new HttpClient
         {
             BaseAddress = url,
             Timeout     = TimeSpan.FromMilliseconds(FibSystemProperties.GetHttpTimeout()),
         });
     }
 }
示例#4
0
        public Connection(Uri url, bool insecure, IEventHandlers eventHandlers = null)
        {
            _eventHandlers = eventHandlers;
            var      proxy  = FibSystemProperties.GetHttpProxy();
            WebProxy proxy1 = null;

            if (!string.IsNullOrEmpty(proxy))
            {
                proxyLog = $"use proxy:{proxy}";
                if (proxy.Contains("@_@"))
                {
                    //127.0.0.1:8080@_@username&pass
                    var arr = proxy.Split(new string[] { "@_@" }, StringSplitOptions.None);
                    proxy1 = new WebProxy
                    {
                        Address               = new Uri($"http://{arr}"),
                        BypassProxyOnLocal    = false,
                        UseDefaultCredentials = false,

                        // *** These creds are given to the proxy server, not the web server ***
                        Credentials = new NetworkCredential(
                            userName: arr[1].Split('&')[0],
                            password: arr[1].Split('&')[1])
                    };
                }
                else
                {
                    proxy1 = new WebProxy
                    {
                        Address               = new Uri($"http://{proxy}"),
                        BypassProxyOnLocal    = false,
                        UseDefaultCredentials = false,
                    };
                }
            }



            if (insecure)
            {
                if (proxy1 != null)
                {
                    client = insecureClients.GetOrAdd(url, _ =>
                    {
                        var httpClientHandler = new HttpClientHandler
                        {
                            Proxy = proxy1, ServerCertificateCustomValidationCallback = (_____, __, ___, ____) => true
                        };
                        var c = new HttpClient(httpClientHandler)
                        {
                            BaseAddress = url,
                            Timeout     = TimeSpan.FromMilliseconds(FibSystemProperties.GetHttpTimeout()),
                        };
                        return(c);
                    });
                }
                else
                {
                    client = insecureClients.GetOrAdd(url, _ => new HttpClient(insecureHandler)
                    {
                        BaseAddress = url,
                        Timeout     = TimeSpan.FromMilliseconds(FibSystemProperties.GetHttpTimeout()),
                    });
                }
            }
            else
            {
                if (proxy1 != null)
                {
                    client = clients.GetOrAdd(url, _ =>
                    {
                        var httpClientHandler = new HttpClientHandler
                        {
                            Proxy = proxy1,
                        };
                        var c = new HttpClient(httpClientHandler)
                        {
                            BaseAddress = url,
                            Timeout     = TimeSpan.FromMilliseconds(FibSystemProperties.GetHttpTimeout()),
                        };
                        return(c);
                    });
                }
                else
                {
                    client = clients.GetOrAdd(url, _ => new HttpClient
                    {
                        BaseAddress = url,
                        Timeout     = TimeSpan.FromMilliseconds(FibSystemProperties.GetHttpTimeout()),
                    });
                }
            }
        }
示例#5
0
 public void TestCheckHttpTimeoutProperty_ok()
 {
     Assert.IsNull(Environment.GetEnvironmentVariable(FibSystemProperties.HttpTimeout));
     FibSystemProperties.CheckHttpTimeoutProperty();
 }