async Task <T> ExecutePostAsync <T>(string requestUri, HttpContent content, bool handlerEncrypted = true) where T : class
        {
            HttpClient client = ConfigureHttpClient(handlerEncrypted);

            TimeSpan timeSpan = _minimunTimeUntilFail;

            if (content is StreamContent)
            {
                timeSpan = _maximunTimeUntilFail;
            }

            CancellationToken cts           = new CancellationTokenSource(timeSpan).Token;
            TimeoutPolicy     timeOutPolicy = Policy.TimeoutAsync(timeSpan);

            using (content)
                using (HttpResponseMessage response = await timeOutPolicy.WrapAsync(_policy).ExecuteAsync(async() => await client.PostAsync(requestUri, content, cts)))
                {
                    return(await ProcessResponse <T>(response));
                }
        }
        /// <summary>
        /// Build default circuit breaker, wait and retry and Timeout policy.
        /// </summary>
        /// <param name="transientPolicySettings">retry,timeout and circuit breaker settings.</param>
        /// <returns>policy wrapper.</returns>
        public virtual PolicyWrap <HttpResponseMessage> GetDefaultPolicy(TransientPolicySettings transientPolicySettings)
        {
            //Time out policy to set Http Client request timeout.
            TimeoutPolicy timeoutPolicy = Policy.TimeoutAsync(TimeSpan.FromSeconds(transientPolicySettings.HttpTimeOut), timeoutStrategy: TimeoutStrategy.Pessimistic, TimeOutHandler);
            //If http client requiest fails, it will be retried.
            IAsyncPolicy <HttpResponseMessage> retryPolicy = Policy.HandleResult <HttpResponseMessage>(r => !r.IsSuccessStatusCode)
                                                             .Or <HttpRequestException>()
                                                             .WaitAndRetryAsync(transientPolicySettings.RetryAttempts, retryafter => TimeSpan.FromSeconds(Math.Pow(2, retryafter) / 2), OnRetry);
            //Circuit breaker to fail fast.
            IAsyncPolicy <HttpResponseMessage> cb = HttpPolicyExtensions
                                                    .HandleTransientHttpError()
                                                    .AdvancedCircuitBreakerAsync(
                transientPolicySettings.CircuitBreakerSettings.FailureThreshold,
                TimeSpan.FromSeconds(transientPolicySettings.CircuitBreakerSettings.SamplingDuration),
                transientPolicySettings.CircuitBreakerSettings.MinimumThroughput,
                TimeSpan.FromSeconds(transientPolicySettings.CircuitBreakerSettings.DurationOfBreak),
                OnBreak,
                OnReset,
                OnHalfOpen);

            //above policies are wrapped.
            return(timeoutPolicy.WrapAsync(retryPolicy.WrapAsync(cb)));
        }