Exemplo n.º 1
0
        public void GetProxiesForUri()
        {
            var proxies = CFNetwork.GetProxiesForUri(uri, settings);

            Assert.That(proxies.Length, Is.EqualTo(1), "single");
            var p = proxies [0];

            Assert.Null(p.AutoConfigurationJavaScript, "AutoConfigurationJavaScript");
            Assert.Null(p.AutoConfigurationUrl, "AutoConfigurationUrl");
            Assert.Null(p.HostName, "HostName");
            Assert.That(p.Port, Is.EqualTo(0), "Port");
            Assert.Null(p.Password, "Password");
            Assert.That(p.ProxyType, Is.EqualTo(CFProxyType.None), "Type");
            Assert.Null(p.Username, "Username");
        }
Exemplo n.º 2
0
        public void Bug_7923()
        {
            // Bug #7923 - crash when proxy is in effect.
            var uri = new Uri("http://www.google.com");

            if (CFNetwork.GetProxiesForUri(uri, settings).Length <= 1)
            {
                Assert.Ignore("Only run when proxy is configured.");
            }

            var req = new HttpWebRequest(uri);

            using (var rsp = req.GetResponse())
                using (var str = new StreamReader(rsp.GetResponseStream()))
                    Console.WriteLine(str.ReadToEnd());
        }
Exemplo n.º 3
0
            public Uri GetProxy(Uri targetUri)
            {
                NetworkCredential credentials = null;
                Uri proxy = null;

                if (targetUri == null)
                {
                    throw new ArgumentNullException("targetUri");
                }

                try {
                    CFProxySettings settings = CFNetwork.GetSystemProxySettings();
                    CFProxy[]       proxies  = CFNetwork.GetProxiesForUri(targetUri, settings);

                    if (proxies != null)
                    {
                        for (int i = 0; i < proxies.Length && proxy == null; i++)
                        {
                            switch (proxies[i].ProxyType)
                            {
                            case CFProxyType.AutoConfigurationJavaScript:
                                proxy = GetProxyUriFromScript(proxies[i].AutoConfigurationJavaScript, targetUri, out credentials);
                                break;

                            case CFProxyType.AutoConfigurationUrl:
                                proxy = ExecuteProxyAutoConfigurationURL(proxies[i].AutoConfigurationUrl, targetUri, out credentials);
                                break;

                            case CFProxyType.HTTPS:
                            case CFProxyType.HTTP:
                            case CFProxyType.FTP:
                                // create a Uri based on the hostname/port/etc info
                                proxy = GetProxyUri(proxies[i], out credentials);
                                break;

                            case CFProxyType.SOCKS:
                                // unsupported proxy type, try the next one
                                break;

                            case CFProxyType.None:
                                // no proxy should be used
                                proxy = targetUri;
                                break;
                            }
                        }

                        if (proxy == null)
                        {
                            // no supported proxies for this Uri, fall back to trying to connect to targetUri directly
                            proxy = targetUri;
                        }
                    }
                    else
                    {
                        proxy = targetUri;
                    }
                } catch {
                    // ignore errors while retrieving proxy data
                    proxy = targetUri;
                }

                if (!userSpecified)
                {
                    this.credentials = credentials;
                }

                return(proxy);
            }