public bool ShouldProxyBeBypassed(HttpProxySettings proxySettings, HttpUri url)
        {
            //We are utilising the WebProxy implementation here to save us having to reimplement it. This way we use Microsofts implementation
            var proxy = new WebProxy(proxySettings.Host + ":" + proxySettings.Port, proxySettings.BypassLocalAddress, proxySettings.BypassListAsArray);

            return proxy.IsBypassed((Uri)url);
        }
Пример #2
0
        public IWebProxy GetWebProxy(HttpProxySettings proxySettings)
        {
            var proxy = _webProxyCache.Get(proxySettings.Key, () => CreateWebProxy(proxySettings), TimeSpan.FromMinutes(5));

            _webProxyCache.ClearExpired();

            return(proxy);
        }
Пример #3
0
        public IWebProxy GetWebProxy(HttpProxySettings proxySettings)
        {
            var proxy = _webProxyCache.Get(proxySettings.Key, () => CreateWebProxy(proxySettings), TimeSpan.FromMinutes(5));

            _webProxyCache.ClearExpired();

            return proxy;
        }
Пример #4
0
        private Uri GetProxyUri(HttpProxySettings proxySettings)
        {
            switch (proxySettings.Type)
            {
            case ProxyType.Http:
                return(new Uri("http://" + proxySettings.Host + ":" + proxySettings.Port));

            case ProxyType.Socks4:
                return(new Uri("socks4://" + proxySettings.Host + ":" + proxySettings.Port));

            case ProxyType.Socks5:
                return(new Uri("socks5://" + proxySettings.Host + ":" + proxySettings.Port));

            default:
                return(null);
            }
        }
Пример #5
0
        private IWebProxy CreateWebProxy(HttpProxySettings proxySettings)
        {
            var uri = GetProxyUri(proxySettings);

            if (uri == null)
            {
                return(null);
            }

            if (proxySettings.Username.IsNotNullOrWhiteSpace() && proxySettings.Password.IsNotNullOrWhiteSpace())
            {
                return(new WebProxy(uri, proxySettings.BypassLocalAddress, proxySettings.BypassListAsArray, new NetworkCredential(proxySettings.Username, proxySettings.Password)));
            }
            else
            {
                return(new WebProxy(uri, proxySettings.BypassLocalAddress, proxySettings.BypassListAsArray));
            }
        }
Пример #6
0
        private IWebProxy CreateWebProxy(HttpProxySettings proxySettings)
        {
            switch (proxySettings.Type)
            {
                case ProxyType.Http:
                    if (proxySettings.Username.IsNotNullOrWhiteSpace() && proxySettings.Password.IsNotNullOrWhiteSpace())
                    {
                        return new WebProxy(proxySettings.Host + ":" + proxySettings.Port, proxySettings.BypassLocalAddress, proxySettings.BypassListAsArray, new NetworkCredential(proxySettings.Username, proxySettings.Password));
                    }
                    else
                    {
                        return new WebProxy(proxySettings.Host + ":" + proxySettings.Port, proxySettings.BypassLocalAddress, proxySettings.BypassListAsArray);
                    }
                case ProxyType.Socks4:
                    return new SocksWebProxy(new ProxyConfig(IPAddress.Loopback, GetNextFreePort(), GetProxyIpAddress(proxySettings.Host), proxySettings.Port, ProxyConfig.SocksVersion.Four, proxySettings.Username, proxySettings.Password), false);
                case ProxyType.Socks5:
                    return new SocksWebProxy(new ProxyConfig(IPAddress.Loopback, GetNextFreePort(), GetProxyIpAddress(proxySettings.Host), proxySettings.Port, ProxyConfig.SocksVersion.Five, proxySettings.Username, proxySettings.Password), false);
            }

            return null;
        }
        public HttpProxySettings GetProxySettings(HttpRequest request)
        {
            if (!_configService.ProxyEnabled)
            {
                return null;
            }

            var proxySettings = new HttpProxySettings(_configService.ProxyType,
                                _configService.ProxyHostname,
                                _configService.ProxyPort,
                                _configService.ProxyBypassFilter,
                                _configService.ProxyBypassLocalAddresses,
                                _configService.ProxyUsername,
                                _configService.ProxyPassword);

            if (ShouldProxyBeBypassed(proxySettings, request.Url))
            {
                return null;
            }

            return proxySettings;
        }
Пример #8
0
        private IWebProxy CreateWebProxy(HttpProxySettings proxySettings)
        {
            switch (proxySettings.Type)
            {
            case ProxyType.Http:
                if (proxySettings.Username.IsNotNullOrWhiteSpace() && proxySettings.Password.IsNotNullOrWhiteSpace())
                {
                    return(new WebProxy(proxySettings.Host + ":" + proxySettings.Port, proxySettings.BypassLocalAddress, proxySettings.BypassListAsArray, new BasicNetworkCredential(proxySettings.Username, proxySettings.Password)));
                }
                else
                {
                    return(new WebProxy(proxySettings.Host + ":" + proxySettings.Port, proxySettings.BypassLocalAddress, proxySettings.BypassListAsArray));
                }

            case ProxyType.Socks4:
                return(new SocksWebProxy(new ProxyConfig(IPAddress.Loopback, GetNextFreePort(), GetProxyIpAddress(proxySettings.Host), proxySettings.Port, ProxyConfig.SocksVersion.Four, proxySettings.Username, proxySettings.Password), false));

            case ProxyType.Socks5:
                return(new SocksWebProxy(new ProxyConfig(IPAddress.Loopback, GetNextFreePort(), GetProxyIpAddress(proxySettings.Host), proxySettings.Port, ProxyConfig.SocksVersion.Five, proxySettings.Username, proxySettings.Password), false));
            }

            return(null);
        }