示例#1
0
        internal static ServicePoint FindServicePoint(ProxyChain chain)
        {
            if (!chain.Enumerator.MoveNext())
            {
                return(null);
            }
            Uri current = chain.Enumerator.Current;

            return(FindServicePointHelper((current == null) ? chain.Destination : current, current != null));
        }
        // Returns null if we get to the end of the chain.
        internal static ServicePoint FindServicePoint(ProxyChain chain)
        {
            GlobalLog.Print("ServicePointManager::FindServicePoint() Calling chained version.");
            if (!chain.Enumerator.MoveNext())
            {
                return(null);
            }

            Uri proxyAddress = chain.Enumerator.Current;

            return(FindServicePointHelper(proxyAddress == null ? chain.Destination : proxyAddress, proxyAddress != null));
        }
示例#3
0
        internal static ServicePoint FindServicePoint(Uri address, IWebProxy proxy, out ProxyChain chain, ref HttpAbortDelegate abortDelegate, ref int abortState)
        {
            if (address == null)
            {
                throw new ArgumentNullException("address");
            }
            bool isProxyServicePoint = false;

            chain = null;
            Uri current = null;

            if ((proxy != null) && !address.IsLoopback)
            {
                IAutoWebProxy proxy2 = proxy as IAutoWebProxy;
                if (proxy2 != null)
                {
                    chain         = proxy2.GetProxies(address);
                    abortDelegate = chain.HttpAbortDelegate;
                    try
                    {
                        Thread.MemoryBarrier();
                        if (abortState != 0)
                        {
                            Exception exception = new WebException(NetRes.GetWebStatusString(WebExceptionStatus.RequestCanceled), WebExceptionStatus.RequestCanceled);
                            throw exception;
                        }
                        chain.Enumerator.MoveNext();
                        current = chain.Enumerator.Current;
                    }
                    finally
                    {
                        abortDelegate = null;
                    }
                }
                else if (!proxy.IsBypassed(address))
                {
                    current = proxy.GetProxy(address);
                }
                if (current != null)
                {
                    address             = current;
                    isProxyServicePoint = true;
                }
            }
            return(FindServicePointHelper(address, isProxyServicePoint));
        }
        // If abortState becomes non-zero, the attempt to find a service point has been aborted.
        internal static ServicePoint FindServicePoint(Uri address, IWebProxy proxy, out ProxyChain chain, ref HttpAbortDelegate abortDelegate, ref int abortState)
        {
            if (address == null)
            {
                throw new ArgumentNullException("address");
            }
            GlobalLog.Enter("ServicePointManager::FindServicePoint() address:" + address.ToString());

            bool isProxyServicePoint = false;

            chain = null;

            //
            // find proxy info, and then switch on proxy
            //
            Uri proxyAddress = null;

            if (proxy != null && !address.IsLoopback)
            {
                IAutoWebProxy autoProxy = proxy as IAutoWebProxy;
                if (autoProxy != null)
                {
                    chain = autoProxy.GetProxies(address);

                    // Set up our ability to abort this MoveNext call.  Note that the current implementations of ProxyChain will only
                    // take time on the first call, so this is the only place we do this.  If a new ProxyChain takes time in later
                    // calls, this logic should be copied to other places MoveNext is called.
                    GlobalLog.Assert(abortDelegate == null, "ServicePointManager::FindServicePoint()|AbortDelegate already set.");
                    abortDelegate = chain.HttpAbortDelegate;
                    try
                    {
                        Thread.MemoryBarrier();
                        if (abortState != 0)
                        {
                            Exception exception = new WebException(NetRes.GetWebStatusString(WebExceptionStatus.RequestCanceled), WebExceptionStatus.RequestCanceled);
                            GlobalLog.LeaveException("ServicePointManager::FindServicePoint() Request aborted before proxy lookup.", exception);
                            throw exception;
                        }

                        if (!chain.Enumerator.MoveNext())
                        {
                            GlobalLog.Assert("ServicePointManager::FindServicePoint()|GetProxies() returned zero proxies.");

/*
 *                          Exception exception = new WebException(NetRes.GetWebStatusString(WebExceptionStatus.RequestProhibitedByProxy), WebExceptionStatus.RequestProhibitedByProxy);
 *                          GlobalLog.LeaveException("ServicePointManager::FindServicePoint() Proxy prevented request.", exception);
 *                          throw exception;
 */
                        }
                        proxyAddress = chain.Enumerator.Current;
                    }
                    finally
                    {
                        abortDelegate = null;
                    }
                }
                else if (!proxy.IsBypassed(address))
                {
                    // use proxy support
                    // rework address
                    proxyAddress = proxy.GetProxy(address);
                }

                // null means DIRECT
                if (proxyAddress != null)
                {
                    address             = proxyAddress;
                    isProxyServicePoint = true;
                }
            }

            ServicePoint servicePoint = FindServicePointHelper(address, isProxyServicePoint);

            GlobalLog.Leave("ServicePointManager::FindServicePoint() servicePoint#" + ValidationHelper.HashString(servicePoint));
            return(servicePoint);
        }
 internal ProxyEnumerator(ProxyChain chain)
 {
     m_Chain = chain;
 }