GetSystemHttpProxyHost() static private method

システムプロキシに設定されたHTTPプロキシのホスト名を取得。
static private GetSystemHttpProxyHost ( ) : string
return string
Exemplo n.º 1
0
        private static void readGatewayConfig()
        {
            if (UpstreamProxyConfig.Type == ProxyConfigType.DirectAccess)
            {
                useHttpGateway  = false;
                useHttpsGateway = false;
                return;
            }

            string httpHost  = "";
            int    httpPort  = 0;
            string httpsHost = "";
            int    httpsPort = 0;

            if (UpstreamProxyConfig.Type == ProxyConfigType.SpecificProxy)
            {
                httpHost  = UpstreamProxyConfig.SpecificProxyHost;
                httpPort  = UpstreamProxyConfig.SpecificProxyPort;
                httpsHost = httpHost;
                httpsPort = httpPort;
            }
            else
            {
                httpHost = WinInetUtil.GetSystemHttpProxyHost();
                httpPort = WinInetUtil.GetSystemHttpProxyPort();
                if (httpPort == ListeningPort && httpHost.IsLoopbackHost())
                {
                    httpHost = "";
                }

                httpsHost = WinInetUtil.GetSystemHttpsProxyHost();
                httpsPort = WinInetUtil.GetSystemHttpsProxyPort();
                if (httpsPort == ListeningPort && httpsHost.IsLoopbackHost())
                {
                    httpsHost = "";
                }
            }

            useHttpGateway  = !string.IsNullOrEmpty(httpHost);
            useHttpsGateway = !string.IsNullOrEmpty(httpsHost);

            if (useHttpGateway)
            {
                httpGateway = httpHost.Contains(":") ? string.Format("[{0}]:{1}", httpHost, httpPort) : string.Format("{0}:{1}", httpHost, httpPort);
            }
            if (useHttpsGateway)
            {
                httpsGateway = httpsHost.Contains(":") ? string.Format("[{0}]:{1}", httpsHost, httpsPort) : string.Format("{0}:{1}", httpsHost, httpsPort);
            }
        }
Exemplo n.º 2
0
        private void SetUpstreamProxy()
        {
            this.RelayHttpProxyHost = null;
            this.RelayHttpProxyPort = 80;

            var config = UpstreamProxyConfig;

            if (config.Type == ProxyConfigType.DirectAccess)
            {
                return;
            }

            if (config.Type == ProxyConfigType.SpecificProxy)
            {
                this.RelayHttpProxyHost = string.IsNullOrWhiteSpace(config.SpecificProxyHost) ? null : config.SpecificProxyHost;
                this.RelayHttpProxyPort = config.SpecificProxyPort;
                return;
            }

            // システムプロキシ利用(既定)
            var requestUri = this.GetEffectiveRequestUri();

            if (requestUri != null)
            {
                var systemProxyConfig = WebRequest.GetSystemWebProxy();
                if (systemProxyConfig.IsBypassed(requestUri))
                {
                    return;                                           //ダイレクトアクセス
                }
                var systemProxy = systemProxyConfig.GetProxy(requestUri);

                this.RelayHttpProxyHost = !systemProxy.IsOwnProxy() ? systemProxy.Host : null;
                this.RelayHttpProxyPort = systemProxy.Port;
            }
            else
            {
                //リクエストURIをうまく組み立てられなかった場合、自動構成は諦めて通常のプロキシ設定を適用
                var systemProxyHost = WinInetUtil.GetSystemHttpProxyHost();
                var systemProxyPort = WinInetUtil.GetSystemHttpProxyPort();
                if (systemProxyPort == HttpProxy.ListeningPort && systemProxyHost.IsLoopbackHost())
                {
                    return; //自身が指定されていた場合上流には指定しない
                }
                this.RelayHttpProxyHost = systemProxyHost;
                this.RelayHttpProxyPort = systemProxyPort;
            }
        }
Exemplo n.º 3
0
        private void SetUpstreamProxy()
        {
            this.RelayHttpProxyHost = null;
            this.RelayHttpProxyPort = 80;

            var config = UpstreamProxyConfig;

            if (config.Type == ProxyConfigType.DirectAccess)
            {
                return;
            }

            if (config.Type == ProxyConfigType.SpecificProxy)
            {
                this.RelayHttpProxyHost = string.IsNullOrWhiteSpace(config.SpecificProxyHost) ? null : config.SpecificProxyHost;
                this.RelayHttpProxyPort = config.SpecificProxyPort;
                return;
            }

            var requestUri = this.GetEffectiveRequestUri();

            if (requestUri != null)
            {
                var systemProxyConfig = WebRequest.GetSystemWebProxy();
                if (systemProxyConfig.IsBypassed(requestUri))
                {
                    return;
                }
                var systemProxy = systemProxyConfig.GetProxy(requestUri);

                this.RelayHttpProxyHost = !systemProxy.IsOwnProxy() ? systemProxy.Host : null;
                this.RelayHttpProxyPort = systemProxy.Port;
            }
            else
            {
                var systemProxyHost = WinInetUtil.GetSystemHttpProxyHost();
                var systemProxyPort = WinInetUtil.GetSystemHttpProxyPort();
                if (systemProxyPort == HttpProxy.ListeningPort && systemProxyHost.IsLoopbackHost())
                {
                    return;
                }
                this.RelayHttpProxyHost = systemProxyHost;
                this.RelayHttpProxyPort = systemProxyPort;
            }
        }
Exemplo n.º 4
0
        public static void Startup(int listeningPort, bool useIpV6 = false, bool isSetIEProxySettings = true)
        {
            FiddlerApplication.AfterSessionComplete += TranslateSession;
            FiddlerApplication.BeforeRequest        += ConfigProxy;

            try {
                if (isSetIEProxySettings)
                {
                    WinInetUtil.SetProxyInProcessByUrlmon(listeningPort);
                    var systemProxyHost = WinInetUtil.GetSystemHttpProxyHost();
                    var systemProxyPort = WinInetUtil.GetSystemHttpProxyPort();
                    if (systemProxyPort != listeningPort || systemProxyHost.IsLoopbackHost())
                    {
                        _systemProxyHost = systemProxyHost;
                        _systemProxyPort = systemProxyPort;
                    }
                }

                FiddlerApplication.Startup(listeningPort, FiddlerCoreStartupFlags.OptimizeThreadPool);
            } catch (Exception) {
                Shutdown();
                throw;
            }
        }