Exemplo n.º 1
0
        public WebProxy GetWebProxy(Uri destination)
        {
            if (destination == null)
            {
                throw new ArgumentNullException("destination");
            }

            if (SystemWebProxy == null &&
                DefaultWebProxy == null)
            {
#if LOG4NET
                f_Logger.DebugFormat("GetWebProxy(<{0}>): returning no proxy",
                                     destination);
#endif
                // no proxy
                return(null);
            }

            if (SystemWebProxy == null)
            {
                if (DefaultWebProxy.Address.Scheme.StartsWith("socks") &&
                    destination.Scheme.StartsWith("http"))
                {
#if LOG4NET
                    f_Logger.DebugFormat("GetWebProxy(<{0}>): ignoring " +
                                         "SOCKS proxy for HTTP destination: {1}",
                                         destination, DefaultWebProxy.Address);
#endif
                    return(null);
                }

#if LOG4NET
                f_Logger.DebugFormat("GetWebProxy(<{0}>): returning default proxy: {1}",
                                     destination, DefaultWebProxy.Address);
#endif
                return(DefaultWebProxy);
            }
            var proxyUri = SystemWebProxy.GetProxy(destination);
            if (proxyUri == destination)
            {
#if LOG4NET
                f_Logger.DebugFormat("GetWebProxy(<{0}>): returning no proxy",
                                     destination);
#endif
                // no proxy
                return(null);
            }
#if LOG4NET
            f_Logger.DebugFormat("GetWebProxy(<{0}>): returning system proxy: {1}",
                                 destination, proxyUri);
#endif
            return(new WebProxy(proxyUri));
        }
Exemplo n.º 2
0
        public WebProxy GetWebProxy(Uri destination)
        {
            if (destination == null)
            {
                throw new ArgumentNullException("destination");
            }

            if (SystemWebProxy == null &&
                DefaultWebProxy == null)
            {
#if LOG4NET
                f_Logger.DebugFormat("GetWebProxy(<{0}>): returning no proxy",
                                     destination);
#endif
                // no proxy
                return(null);
            }

            if (SystemWebProxy == null)
            {
#if LOG4NET
                f_Logger.DebugFormat("GetWebProxy(<{0}>): returning default proxy: {1}",
                                     destination, DefaultWebProxy.Address);
#endif
                return(DefaultWebProxy);
            }
            var proxyUri = SystemWebProxy.GetProxy(destination);
            if (proxyUri == destination)
            {
#if LOG4NET
                f_Logger.DebugFormat("GetWebProxy(<{0}>): returning no proxy",
                                     destination);
#endif
                // no proxy
                return(null);
            }
#if LOG4NET
            f_Logger.DebugFormat("GetWebProxy(<{0}>): returning system proxy: {1}",
                                 destination, proxyUri);
#endif
            return(new WebProxy(proxyUri));
        }
Exemplo n.º 3
0
        public void GetCurrentProxyTest()
        {
            var proxy = SystemWebProxy.GetCurrentProxy();

            Assert.IsNotNull(proxy);
        }