Table of Contents

Class RetryAfterValue

Namespace
Trellis
Assembly
Trellis.Results.dll

Represents an RFC 9110 §10.2.3 Retry-After value, which can be either a delay in seconds or an absolute HTTP-date indicating when the client may retry.

public sealed class RetryAfterValue : IEquatable<RetryAfterValue>
Inheritance
RetryAfterValue
Implements
Inherited Members
Extension Methods

Examples

var delay = RetryAfterValue.FromSeconds(60);
var date = RetryAfterValue.FromDate(DateTimeOffset.UtcNow.AddMinutes(5));

// Use in error creation:
Error.RateLimit("Too many requests.", retryAfter: delay)
Error.ServiceUnavailable("Service is under maintenance.", retryAfter: date)

Remarks

The Retry-After header is used with:

  • 429 Too Many Requests — indicates when rate limit resets
  • 503 Service Unavailable — indicates when service may resume
  • 413 Content Too Large — indicates when temporary limit may change
  • 3xx Redirections — indicates minimum wait before following redirect

Create instances using FromSeconds(int) or FromDate(DateTimeOffset). Format for HTTP headers using ToHeaderValue().

Properties

Date

Gets the absolute date. Only valid when IsDate is true.

public DateTimeOffset Date { get; }

Property Value

DateTimeOffset

Exceptions

InvalidOperationException

Thrown when this value represents a delay, not a date.

DelaySeconds

Gets the delay in seconds. Only valid when IsDelaySeconds is true.

public int DelaySeconds { get; }

Property Value

int

Exceptions

InvalidOperationException

Thrown when this value represents a date, not a delay.

IsDate

Gets whether this value represents an absolute HTTP-date (as opposed to a delay).

public bool IsDate { get; }

Property Value

bool

IsDelaySeconds

Gets whether this value represents a delay in seconds (as opposed to an absolute date).

public bool IsDelaySeconds { get; }

Property Value

bool

Methods

Equals(object?)

Determines whether the specified object is equal to the current object.

public override bool Equals(object? obj)

Parameters

obj object

The object to compare with the current object.

Returns

bool

true if the specified object is equal to the current object; otherwise, false.

Equals(RetryAfterValue?)

Indicates whether the current object is equal to another object of the same type.

public bool Equals(RetryAfterValue? other)

Parameters

other RetryAfterValue

An object to compare with this object.

Returns

bool

true if the current object is equal to the other parameter; otherwise, false.

FromDate(DateTimeOffset)

Creates a RetryAfterValue representing an absolute HTTP-date.

public static RetryAfterValue FromDate(DateTimeOffset date)

Parameters

date DateTimeOffset

The date and time when the client may retry.

Returns

RetryAfterValue

A new RetryAfterValue instance.

FromSeconds(int)

Creates a RetryAfterValue representing a delay in seconds.

public static RetryAfterValue FromSeconds(int seconds)

Parameters

seconds int

The number of seconds the client should wait before retrying. Must be non-negative.

Returns

RetryAfterValue

A new RetryAfterValue instance.

Exceptions

ArgumentOutOfRangeException

Thrown when seconds is negative.

GetHashCode()

Serves as the default hash function.

public override int GetHashCode()

Returns

int

A hash code for the current object.

ToHeaderValue()

Formats this value for use as an HTTP Retry-After header value. Returns either a decimal number of seconds or an HTTP-date in IMF-fixdate format.

public string ToHeaderValue()

Returns

string

The formatted header value string.

ToString()

Returns a string that represents the current object.

public override string ToString()

Returns

string

A string that represents the current object.