Exemple #1
0
        /// <summary>
        /// Initializes a MultiProxy instance that lazily parses a given WinHTTP configuration string.
        /// </summary>
        /// <param name="proxyConfig">The WinHTTP proxy config to parse.</param>
        /// <param name="secure">If true, return proxies suitable for use with a secure connection. If false, return proxies suitable for an insecure connection.</param>
        public static MultiProxy CreateLazy(FailedProxyCache failedProxyCache, string proxyConfig, bool secure)
        {
            Debug.Assert(failedProxyCache != null);

            return(string.IsNullOrEmpty(proxyConfig) == false ?
                   new MultiProxy(failedProxyCache, proxyConfig, secure) :
                   MultiProxy.Empty);
        }
Exemple #2
0
 private MultiProxy(FailedProxyCache failedProxyCache, string proxyConfig, bool secure)
 {
     _failedProxyCache = failedProxyCache;
     _uris             = null;
     _proxyConfig      = proxyConfig;
     _secure           = secure;
     _currentIndex     = 0;
     _currentUri       = null;
 }
Exemple #3
0
 private MultiProxy(FailedProxyCache failedProxyCache, Uri[] uris)
 {
     _failedProxyCache = failedProxyCache;
     _uris             = uris;
     _proxyConfig      = null;
     _secure           = default;
     _currentIndex     = 0;
     _currentUri       = null;
 }
Exemple #4
0
        /// <summary>
        /// Parses a WinHTTP proxy config into a MultiProxy instance.
        /// </summary>
        /// <param name="proxyConfig">The WinHTTP proxy config to parse.</param>
        /// <param name="secure">If true, return proxies suitable for use with a secure connection. If false, return proxies suitable for an insecure connection.</param>
        public static MultiProxy Parse(FailedProxyCache failedProxyCache, string?proxyConfig, bool secure)
        {
            Debug.Assert(failedProxyCache != null);

            Uri[] uris = Array.Empty <Uri>();

            ReadOnlySpan <char> span = proxyConfig;

            while (TryParseProxyConfigPart(span, secure, out Uri? uri, out int charactersConsumed))
            {
                int idx = uris.Length;

                // Assume that we will typically not have more than 1...3 proxies, so just
                // grow by 1. This method is currently only used once per process, so the
                // case of an abnormally large config will not be much of a concern anyway.
                Array.Resize(ref uris, idx + 1);
                uris[idx] = uri;

                span = span.Slice(charactersConsumed);
            }

            return(new MultiProxy(failedProxyCache, uris));
        }