Class HttpShield
Building blocks for HTTP resilience shields.
public static class HttpShield
- Inheritance
-
HttpShield
- Inherited Members
Methods
IsTransient(HttpResponseMessage)
Returns true for responses worth retrying: 5xx, 408 Request Timeout and 429 Too Many Requests.
public static bool IsTransient(HttpResponseMessage response)
Parameters
responseHttpResponseMessage
Returns
IsTransientException(Exception?, CancellationToken)
Returns true for transient HTTP exceptions, including an
Timeout cancellation when callerCancellationToken
was not cancelled.
public static bool IsTransientException(Exception? exception, CancellationToken callerCancellationToken)
Parameters
exceptionExceptioncallerCancellationTokenCancellationToken
Returns
RetryAfter(RetryEvent<HttpResponseMessage>)
A DelayGenerator honouring the response's
Retry-After header when present and longer than the computed backoff, capped at the
default backoff's 30-second maximum.
public static ValueTask<TimeSpan?> RetryAfter(RetryEvent<HttpResponseMessage> retry)
Parameters
retryRetryEvent<HttpResponseMessage>
Returns
RetryAfter(TimeSpan)
Creates a DelayGenerator that honours
Retry-After while capping the server suggestion at maxDelay.
The computed backoff is never shortened.
public static Func<RetryEvent<HttpResponseMessage>, ValueTask<TimeSpan?>> RetryAfter(TimeSpan maxDelay)
Parameters
maxDelayTimeSpan
Returns
Exceptions
- ArgumentOutOfRangeException
maxDelayis negative.
Standard()
A production-ready pipeline, outermost first: 30s total timeout → 3 retries with
exponential jittered backoff honouring Retry-After headers (retried responses are
disposed) → circuit breaker (50% failure ratio over 30s, minimum 10 calls, 15s break) →
10s per-attempt timeout.
public static Shield<HttpResponseMessage> Standard()
Returns
Standard(StandardHttpShieldOptions)
Builds the standard HTTP pipeline from options.
public static Shield<HttpResponseMessage> Standard(StandardHttpShieldOptions options)
Parameters
optionsStandardHttpShieldOptions
Returns
WhenTransient()
Starts a shield that handles the usual transient HTTP failures: HttpRequestException, Timeout cancellations, Kevlar attempt timeouts, 5xx, 408 and 429. Chain your strategies onto the returned builder.
public static ShieldBuilder<HttpResponseMessage> WhenTransient()