Example #1
0
 public HttpClientWrapper(HttpClientConfiguration httpClientConfig)
 {
     this.client = new HttpClient()
     {
         Timeout = httpClientConfig.Timeout
     };
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="HttpClientWrapper"/> class.
        /// </summary>
        /// <param name="httpClientConfig"> HttpClientConfiguration object.</param>
        public HttpClientWrapper(HttpClientConfiguration httpClientConfig)
        {
            this.client = httpClientConfig.HttpClientInstance;
            this.overrideHttpClientConfiguration = httpClientConfig.OverrideHttpClientConfiguration;

            if (overrideHttpClientConfiguration)
            {
                this.statusCodesToRetry = httpClientConfig.StatusCodesToRetry
                                          .Where(val => Enum.IsDefined(typeof(HttpStatusCode), val))
                                          .Select(val => (HttpStatusCode)val).ToImmutableList();

                this.requestMethodsToRetry = httpClientConfig.RequestMethodsToRetry
                                             .Select(method => new HttpMethod(method.ToString())).ToList();

                this.numberOfRetries      = httpClientConfig.NumberOfRetries;
                this.backoffFactor        = httpClientConfig.BackoffFactor;
                this.retryInterval        = httpClientConfig.RetryInterval;
                this.maximumRetryWaitTime = httpClientConfig.MaximumRetryWaitTime;
                this.client.Timeout       = httpClientConfig.Timeout;
            }
        }