question 307 HTTP & API Clients · medium
How long does Retry-After say to wait?
HTTP allows two forms of the Retry-After header: a number of seconds ("120") or a date ("Wed, 21 Oct 2026 07:28:00 GMT"). Write retry_after_seconds(value, now): return how many seconds to wait from now, as a float, never less than 0. Return None for a value that is neither form.
Function
retry_after_seconds(value, now)valuethe header text, possibly with spaces around it
nowthe current time as ISO text with a zone, e.g.
"2026-10-21T07:26:30+00:00"Returnsseconds as a float (
120.0, 90.0), 0.0 for a date in the past, None for anything else (including negative numbers)Examples
callretry_after_seconds('120', '2026-10-21T07:26:30+00:00')returns120.0
callretry_after_seconds('Wed, 21 Oct 2026 07:28:00 GMT', '2026-10-21T07:26:30+00:00')returns90.0
callretry_after_seconds('soon', '2026-10-21T07:26:30+00:00')returnsNone