Пример #1
0
        internal BlockingRequestHandler(Client client, TimeSpan timeout, HttpClient httpClient, Backo backo)
#endif
        {
            this._client = client;
            _backo       = backo;

            this.Timeout = timeout;

            if (httpClient != null)
            {
                _httpClient = httpClient;
            }
            // Create HttpClient instance in .Net 3.5
#if NET35
            if (httpClient == null)
            {
                _httpClient = new HttpClient {
                    Timeout = Timeout
                }
            }
            ;
#else
            var handler = new HttpClientHandler();
#endif

            // Set proxy information
            if (!string.IsNullOrEmpty(_client.Config.Proxy))
            {
#if NET35
                _httpClient.Proxy = new WebProxy(_client.Config.Proxy);
#else
                handler.Proxy    = new WebProxy(_client.Config.Proxy);
                handler.UseProxy = true;
#endif
            }

            // Initialize HttpClient instance with given configuration
#if !NET35
            if (httpClient == null)
            {
                _httpClient = new HttpClient(handler)
                {
                    Timeout = Timeout
                }
            }
            ;
#endif
            // Send user agent in the form of {library_name}/{library_version} as per RFC 7231.
            var szUserAgent = _client.Config.UserAgent;
#if NET35
            _httpClient.Headers.Set("User-Agent", szUserAgent);
#else
            _httpClient.DefaultRequestHeaders.Add("User-Agent", szUserAgent);
#endif
        }
Пример #2
0
 internal BlockingRequestHandler(Client client, TimeSpan timeout, IHttpClient httpClient, Backo backo)
Пример #3
0
 internal BlockingRequestHandler(Client client, TimeSpan timeout, Backo backo) : this(client, timeout, null, backo)
 {
 }