Example #1
0
        public void WebProxy()
        {
            IWebProxy proxy = PlatformCFNetwork.GetDefaultProxy();

            Assert.True(proxy.IsBypassed(uri), "IsBypassed");
            Assert.That(proxy.GetProxy(uri), Is.SameAs(uri), "GetProxy");
        }
Example #2
0
        public void GetProxiesForUri()
        {
            var proxies = PlatformCFNetwork.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");
        }
Example #3
0
        public void Bug_7923()
        {
            // Bug #7923 - crash when proxy is in effect.
            var uri = new Uri("http://www.google.com");

            if (PlatformCFNetwork.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());
        }
Example #4
0
        public void Bug_7923()
        {
            // Bug #7923 - crash when proxy is in effect.
            var uri = NetworkResources.MicrosoftUri;

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

            var req = WebRequest.CreateHttp(uri);

            using (var rsp = req.GetResponse())
                using (var str = new StreamReader(rsp.GetResponseStream()))
                    Console.WriteLine(str.ReadToEnd());
        }
Example #5
0
            static Uri GetProxyUriFromScript(NSString script, Uri targetUri, out NetworkCredential credentials)
            {
                CFProxy[] proxies = CFNetwork.GetProxiesForAutoConfigurationScript(script, targetUri);

                if (proxies == null)
                {
                    credentials = null;
                    return(targetUri);
                }

                for (int i = 0; i < proxies.Length; i++)
                {
                    switch (proxies[i].ProxyType)
                    {
                    case CFProxyType.HTTPS:
                    case CFProxyType.HTTP:
                    case CFProxyType.FTP:
                        // create a Uri based on the hostname/port/etc info
                        return(GetProxyUri(proxies[i], out credentials));

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

                    case CFProxyType.None:
                        // no proxy should be used
                        credentials = null;
                        return(targetUri);
                    }
                }

                credentials = null;

                return(null);
            }
Example #6
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:
                                // unsupported proxy type (requires fetching script from remote url)
                                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);
            }