Example #1
0
        /// <summary>Initializes the pool.</summary>
        /// <param name="maxConnections">The maximum number of connections allowed to be associated with the pool at any given time.</param>
        public HttpConnectionPool(HttpConnectionPools pools, HttpConnectionKey key, int maxConnections = int.MaxValue) // int.MaxValue treated as infinite
        {
            _pools          = pools;
            _key            = key;
            _maxConnections = maxConnections;

            // Precalculate ASCII bytes for header name
            // We don't do this for proxy connections because the actual host header varies on a proxy connection.
            if (!pools.UsingProxy)
            {
                // CONSIDER: Cache more than just host name -- port, header name, etc

                // Note the IDN hostname should always be ASCII, since it's already been IDNA encoded.
                _idnHostAsciiBytes = Encoding.ASCII.GetBytes(key.Host);
                Debug.Assert(Encoding.ASCII.GetString(_idnHostAsciiBytes) == key.Host);
            }
            else
            {
                // Proxy connections should never use SSL
                Debug.Assert(!key.IsSecure);
            }

            if (key.IsSecure)
            {
                // Precalculate cached SSL options to use for all connections.
                _sslOptions = _pools.Settings._sslOptions?.ShallowClone() ?? new SslClientAuthenticationOptions();
                _sslOptions.ApplicationProtocols = null;            // explicitly ignore any ApplicationProtocols set
                _sslOptions.TargetHost           = key.SslHostName; // always use the key's name rather than whatever was specified
            }
        }
        public HttpProxyConnectionHandler(HttpConnectionSettings settings, HttpMessageHandler innerHandler)
        {
            Debug.Assert(innerHandler != null);

            _innerHandler       = innerHandler;
            _proxy              = (settings._useProxy && settings._proxy != null) ? settings._proxy : new PassthroughWebProxy(s_proxyFromEnvironment.Value);
            _defaultCredentials = settings._defaultProxyCredentials;
            _connectionPools    = new HttpConnectionPools(settings._maxConnectionsPerServer);
        }
        public HttpProxyConnectionHandler(HttpConnectionSettings settings, HttpMessageHandler innerHandler)
        {
            Debug.Assert(innerHandler != null);
            Debug.Assert(settings._useProxy);

            _innerHandler       = innerHandler;
            _proxy              = settings._proxy ?? ConstructSystemProxy();
            _defaultCredentials = settings._defaultProxyCredentials;
            _connectionPools    = new HttpConnectionPools(settings, settings._maxConnectionsPerServer, usingProxy: true);
        }
Example #4
0
        /// <summary>Initializes the pool.</summary>
        /// <param name="maxConnections">The maximum number of connections allowed to be associated with the pool at any given time.</param>
        public HttpConnectionPool(HttpConnectionPools pools, HttpConnectionKey key, int maxConnections = int.MaxValue) // int.MaxValue treated as infinite
        {
            _pools          = pools;
            _key            = key;
            _maxConnections = maxConnections;

            // Precalculate ASCII bytes for header name
            // We don't do this for proxy connections because the actual host header varies on a proxy connection.
            if (!pools.UsingProxy)
            {
                // CONSIDER: Cache more than just host name -- port, header name, etc
                _idnHostAsciiBytes = Encoding.ASCII.GetBytes(key.Host);
            }
            else
            {
                // Proxy connections should never use SSL
                Debug.Assert(!key.IsSecure);
            }
        }
 public HttpConnectionHandler(HttpConnectionSettings settings)
 {
     _settings        = settings;
     _connectionPools = new HttpConnectionPools(settings._maxConnectionsPerServer);
 }
Example #6
0
 public HttpConnectionHandler(HttpConnectionSettings settings)
 {
     _connectionPools = new HttpConnectionPools(settings, usingProxy: false);
 }
 public HttpConnectionHandler(HttpConnectionSettings settings)
 {
     _connectionPools = new HttpConnectionPools(settings, settings._maxConnectionsPerServer, usingProxy: false);
 }