Class RetryDelegatingHandler
- Namespace
- MADE.Networking.Http
- Assembly
- MADE.Networking.dll
Defines a delegating handler that retries failed HTTP requests with exponential backoff.
public class RetryDelegatingHandler : DelegatingHandler, IDisposable
- Inheritance
-
RetryDelegatingHandler
- Implements
- Inherited Members
- Extension Methods
Remarks
Use this handler when constructing an HttpClient to automatically retry transient failures.
var handler = new RetryDelegatingHandler(maxRetries: 3, initialDelay: TimeSpan.FromSeconds(1));
var client = new HttpClient(handler);
Constructors
RetryDelegatingHandler(int, TimeSpan?)
Initializes a new instance of the RetryDelegatingHandler class.
public RetryDelegatingHandler(int maxRetries = 3, TimeSpan? initialDelay = null)
Parameters
maxRetriesintThe maximum number of retry attempts. Default is 3.
initialDelayTimeSpan?The initial delay before the first retry. Default is 1 second.
RetryDelegatingHandler(HttpMessageHandler, int, TimeSpan?)
Initializes a new instance of the RetryDelegatingHandler class with the specified inner handler.
public RetryDelegatingHandler(HttpMessageHandler innerHandler, int maxRetries = 3, TimeSpan? initialDelay = null)
Parameters
innerHandlerHttpMessageHandlerThe inner handler which is responsible for processing the HTTP response messages.
maxRetriesintThe maximum number of retry attempts. Default is 3.
initialDelayTimeSpan?The initial delay before the first retry. Default is 1 second.
Properties
InitialDelay
Gets the initial delay before the first retry. Each subsequent retry doubles the delay.
public TimeSpan InitialDelay { get; }
Property Value
MaxRetries
Gets the maximum number of retry attempts.
public int MaxRetries { get; }
Property Value
Methods
SendAsync(HttpRequestMessage, CancellationToken)
Sends an HTTP request to the inner handler to send to the server as an asynchronous operation.
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
Parameters
requestHttpRequestMessageThe HTTP request message to send to the server.
cancellationTokenCancellationTokenA cancellation token to cancel operation.
Returns
- Task<HttpResponseMessage>
The task object representing the asynchronous operation.
Exceptions
- ArgumentNullException
The
requestwas null.- OperationCanceledException
The cancellation token was canceled. This exception is stored into the returned task.