Skip to content

Commit f578f9e

Browse files
author
childish-sambino
authored
feat: allow the RetryDelegatingHandler to be used with HttpClientFactory (#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.
1 parent 0d450ec commit f578f9e

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

src/SendGrid/BaseClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ public async Task<Response> RequestAsync(
234234

235235
private static HttpClient CreateHttpClientWithRetryHandler(BaseClientOptions options)
236236
{
237-
return new HttpClient(new RetryDelegatingHandler(options.ReliabilitySettings));
237+
return new HttpClient(new RetryDelegatingHandler(new HttpClientHandler(), options.ReliabilitySettings));
238238
}
239239

240240
/// <summary>

src/SendGrid/Reliability/RetryDelegatingHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ public class RetryDelegatingHandler : DelegatingHandler
3333
/// </summary>
3434
/// <param name="settings">A ReliabilitySettings instance.</param>
3535
public RetryDelegatingHandler(ReliabilitySettings settings)
36-
: this(new HttpClientHandler(), settings)
3736
{
37+
this.settings = settings;
3838
}
3939

4040
/// <summary>

tests/SendGrid.Tests/Integration.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5872,7 +5872,10 @@ public async Task TestRetryBehaviourThrowsTimeoutException()
58725872
ReliabilitySettings = new ReliabilitySettings(1, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(1))
58735873
};
58745874

5875-
var retryHandler = new RetryDelegatingHandler(new HttpClientHandler(), options.ReliabilitySettings);
5875+
var retryHandler = new RetryDelegatingHandler(options.ReliabilitySettings);
5876+
5877+
// Verify we can set the inner handler after constrcution.
5878+
retryHandler.InnerHandler = new HttpClientHandler();
58765879

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

0 commit comments

Comments
 (0)