RetryAfter

Reads a Retry-After header value: a number of seconds (delay-seconds) or an HTTP-date in any of RFC 9110's three forms.

Stable Core. The grammar is RFC 9110's with three liberties: day and month names and GMT in any ASCII case; SP and HTAB around the value trimmed; a weekday that disagrees with the date ignored. Other zones (UTC, +0000), unpadded days, a four-digit RFC 850 year, signs, fractions, units and non-ASCII digits are rejected. A number saturates at 253,402,300,799 seconds (the instant 9999-12-31T23:59:59Z, the largest delay a date can express), so a huge value is a very long wait and now + delay cannot overflow. A date in the past is Duration.ZERO; the result is never negative. The pause a value causes is capped elsewhere, by maxPause. A failure's message is constant and never echoes the value.

Functions

Link copied to clipboard
fun parse(value: String, nowEpochMillis: Long): Result<Duration>

Reads value against the local clock: a date's delay is the date minus nowEpochMillis.

fun parse(value: String, nowEpochMillis: Long, serverDateEpochMillis: Long): Result<Duration>

Reads value against the server's own clock: a date's delay is the date minus serverDateEpochMillis (the response's Date), so a skewed local clock cancels out of a pair of server readings.