RFC 9110 allows delay-seconds or an HTTP-date in Retry-After. Parse all three date forms, measure against the Date header, cap the wait and add jitter.
One header, two shapes
When a server answers 429 Too Many Requests or 503 Service Unavailable, it can tell the client when to come back with the Retry-After header. Most client code handles the common case, Retry-After: 120, and stops there. RFC 9110 allows a second shape: an HTTP date such as Retry-After: Sat, 28 Nov 2026 10:01:30 GMT. A client that only expects digits either crashes on the date, ignores it and retries immediately, or parses it with its own clock and waits the wrong amount of time.
The difference matters most in exactly the situations where Retry-After is sent: an overloaded service, a rate limit shared by many clients, or a planned maintenance window. A client that retries too early adds load to a service that has just asked for less. A client that waits far too long turns a short throttle into an outage on its own side.
This guide reads the specification, measures how urllib3 2.8.0 handles the edge cases, and builds a small parser in Python and Java that accepts both shapes, survives clock skew, caps the wait and adds jitter.
What RFC 9110 actually allows
Section 10.2.3 defines the field as HTTP-date / delay-seconds. A delay-seconds value is a non-negative decimal integer: one or more digits and nothing else. So 1.5, -5, 0x10 and 120, 60 are all outside the grammar.
An HTTP-date has three forms. Section 5.6.7 prefers IMF-fixdate, Sun, 06 Nov 1994 08:49:37 GMT, and requires senders to generate only that form. Recipients, however, must accept all three, including the obsolete RFC 850 form, Sunday, 06-Nov-94 08:49:37 GMT, and the asctime form, Sun Nov 6 08:49:37 1994. For the two-digit year, a recipient must treat a timestamp that appears more than 50 years in the future as the most recent matching year in the past.
The specification does not set a maximum. A server can legally send Retry-After: 99999999, roughly three years. Every client needs its own cap.
How a mainstream client behaves
urllib3 is the HTTP layer under requests and many SDKs. In release 2.8.0 (15 September 2026), Retry.parse_retry_after accepts an integer with optional whitespace, otherwise tries email.utils.parsedate_tz, and raises InvalidHeader if neither works. A date is converted to seconds by subtracting the local time.time(). The result is clamped at zero and capped at retry_after_max, which defaults to 21,600 seconds, six hours. Retry-After is honoured by default for 413, 429 and 503.
Running the parser in a virtual environment pinned to packages available on 28 November 2026 gave these results:
| Header value | urllib3 2.8.0 result |
|---|---|
120 or 120 | 120 seconds |
1.5, -5, empty, tomorrow, 120, 60 | raises InvalidHeader |
99999999 | 21,600 seconds, the default cap |
| A date 90 seconds ahead of the client clock | 89 seconds |
| A date in the past, or either obsolete form from 1994 | 0 seconds |
Two of those rows deserve attention. First, a six-hour default cap is generous: an interactive client usually wants minutes. Second, the date form is measured against the client clock. In the probe, a server that meant "90 seconds from now" was read by a client whose clock ran 60 seconds fast as a 29-second wait. A client running 10 minutes slow would wait more than 11 minutes.
Use the server clock for the date form
The fix for skew is already in the response. RFC 9110 requires an origin server with a clock to send a Date header, and both Date and Retry-After come from the same server clock. Subtracting one from the other gives the interval the server intended, independent of the client clock. Fall back to the local clock only when Date is missing.
def retry_after_seconds(value, now, server_date=None, cap=300.0):
if value is None:
return None
m = _DIGITS.match(value) # ^\s*([0-9]+)\s*$
if m:
return min(float(int(m.group(1))), cap)
at = parse_http_date(value, now) # IMF-fixdate, RFC 850 or asctime
if at is None:
return None # unusable: caller falls back to its own backoff
reference = parse_http_date(server_date, now) if server_date else None
delay = (at - (reference or now)).total_seconds()
return min(max(delay, 0.0), cap)The companion example retry_after_parse_skew contains the full Python module, its tests and a Java version. The tests pin the skew cases: with a client 60 seconds fast, the local-clock reading is 30 seconds; with the Date header it is 90. With a client 10 minutes slow, the local reading of 690 seconds is capped at 300; with the Date header it is again 90.
The Java version and a parsing trap
Java has no Retry-After helper in java.net.http, so the example parses with java.time. DateTimeFormatter.RFC_1123_DATE_TIME handles IMF-fixdate but not the obsolete forms, so the example uses three explicit patterns with Locale.ROOT.
The RFC 850 form hid a trap. A pattern with yy resolves 94 to 2094, and when the pattern also contains the weekday name, java.time checks that 6 November 2094 is a Sunday before the code can apply the 50-year rule. It is not, so parsing fails. The example drops the weekday text for that one form, parses the date, then subtracts 100 years when the result lies more than 50 years ahead. Python's %y follows the POSIX convention and maps 69 to 99 into the 1900s, so the Python parser reads 94 as 1994 without any correction; the 50-year rule only matters for parsers that resolve every two-digit year into this century.
Use Locale.ROOT or Locale.ENGLISH for the patterns. Under a default locale such as German, EEE and MMM expect localised names and every valid header fails to parse.
Caps, jitter and what to do when the value is unusable
The parsed delay is a hint, not a schedule. Three rules turn it into a wait.
- Cap it at what your caller can tolerate. Five minutes suits a background worker; an interactive request should probably fail fast and tell the user.
- Add jitter on top of the hint, never below it and never past the cap. The example adds up to 10 percent. Without jitter, every client that received the same date returns at the same second and recreates the spike that caused the 429.
- If the value is outside the grammar, ignore it and use capped exponential backoff with full jitter. Treating
1.5as 1.5 seconds is tempting, but a server that sends nonstandard values may also mean something else by them, and the caller's normal backoff is a safe default.
Also count retries. A Retry-After header does not reset the retry budget; a server that sends Retry-After: 1 forever should not keep a client looping forever.
Where it goes wrong in production
At Belgavi's Book Store the catalogue sync calls a supplier inventory API that rate-limits per account. Geetha notices that after a throttle every worker returns at the same second and is throttled again. The cause is a client that treats the date form as unusable and retries at a fixed one-second interval, plus a load balancer that adds Retry-After as an HTTP date during maintenance. Parsing both forms, honouring Date, and adding jitter spreads the returns across the window.
Other failure modes worth testing:
- A proxy strips
Datebut keepsRetry-After. The parser must then fall back to the local clock, and the cap limits the damage from skew. - A cached 503 is replayed by an intermediary with its original headers. The date form then lies in the past, which correctly reads as zero; rely on the retry budget, not on the header, to stop a loop.
- A server sends both a large
Retry-Afterand aRateLimit-Reset-style header. Pick one documented source per API and test it, rather than taking the minimum of several.
Verification checklist
- Unit-test the three date forms, the two-digit-year rule, past dates and every invalid value in the table.
- Test skew in both directions with and without a
Dateheader. - Assert the cap and that jitter never shortens the server hint.
- In an integration test, return 429 with an HTTP-date and confirm the client waits the intended interval.
- Log the parsed delay and its source, header or backoff, so throttling behaviour is visible in production.
A correct Retry-After client is small: two shapes, one reference clock, one cap and some jitter.