Class HttpShield

Namespace
Kevlar.Extensions.Http
Assembly
Kevlar.Extensions.Http.dll

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

response HttpResponseMessage

Returns

bool

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

exception Exception
callerCancellationToken CancellationToken

Returns

bool

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

retry RetryEvent<HttpResponseMessage>

Returns

ValueTask<TimeSpan?>

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

maxDelay TimeSpan

Returns

Func<RetryEvent<HttpResponseMessage>, ValueTask<TimeSpan?>>

Exceptions

ArgumentOutOfRangeException

maxDelay is 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

Shield<HttpResponseMessage>

Standard(StandardHttpShieldOptions)

Builds the standard HTTP pipeline from options.

public static Shield<HttpResponseMessage> Standard(StandardHttpShieldOptions options)

Parameters

options StandardHttpShieldOptions

Returns

Shield<HttpResponseMessage>

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()

Returns

ShieldBuilder<HttpResponseMessage>