Пример #1
0
        public Task <PooledObject <ProxyClientWrapper> > GetClientAsync(Uri uri, TimeSpan?timeout = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            Pool <ProxyClientWrapper> pool = null;

            HostPort key = new HostPort(uri.Host, uri.Port, uri.IsHttps());

            if (!_cachedPools.TryGetValue(key, out pool))
            {
                lock (_lock)
                {
                    if (!_cachedPools.TryGetValue(key, out pool))
                    {
                        pool = new Pool <ProxyClientWrapper>(
                            _size,
                            async cancel => new ProxyClientWrapper(await _proxyClientFactory.Invoke(cancel), key, _callback),
                            whenDropAndNew: client => client.IsBroken);

                        _cachedPools.Add(key, pool);
                    }
                }
            }

            return(pool.GetObjectAsync(timeout, cancellationToken));
        }
Пример #2
0
 internal ProxyClientWrapper(IProxyClient proxyClient, HostPort key, RemoteCertificateValidationCallback callback = null)
 {
     _key         = key;
     _proxyClient = proxyClient;
     _callback    = callback;
 }