Skip to content

Commit

Permalink
feat: allow the RetryDelegatingHandler to be used with `HttpClientF…
Browse files Browse the repository at this point in the history
…actory` (#1030)

A default inner handler should not be created by the delegating handler as required by the client factory. This change moves the creation of `HttpClientHandler` to the base client.
  • Loading branch information
childish-sambino authored Jul 22, 2020
1 parent 0d450ec commit f578f9e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/SendGrid/BaseClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public async Task<Response> RequestAsync(

private static HttpClient CreateHttpClientWithRetryHandler(BaseClientOptions options)
{
return new HttpClient(new RetryDelegatingHandler(options.ReliabilitySettings));
return new HttpClient(new RetryDelegatingHandler(new HttpClientHandler(), options.ReliabilitySettings));
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/SendGrid/Reliability/RetryDelegatingHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public class RetryDelegatingHandler : DelegatingHandler
/// </summary>
/// <param name="settings">A ReliabilitySettings instance.</param>
public RetryDelegatingHandler(ReliabilitySettings settings)
: this(new HttpClientHandler(), settings)
{
this.settings = settings;
}

/// <summary>
Expand Down
5 changes: 4 additions & 1 deletion tests/SendGrid.Tests/Integration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5872,7 +5872,10 @@ public async Task TestRetryBehaviourThrowsTimeoutException()
ReliabilitySettings = new ReliabilitySettings(1, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(1))
};

var retryHandler = new RetryDelegatingHandler(new HttpClientHandler(), options.ReliabilitySettings);
var retryHandler = new RetryDelegatingHandler(options.ReliabilitySettings);

// Verify we can set the inner handler after constrcution.
retryHandler.InnerHandler = new HttpClientHandler();

HttpClient clientToInject = new HttpClient(retryHandler) { Timeout = TimeSpan.FromMilliseconds(1) };
var sg = new SendGridClient(clientToInject, options.ApiKey);
Expand Down

0 comments on commit f578f9e

Please sign in to comment.