Read a Retry-After header
Turn delay-seconds or an HTTP date into milliseconds to wait, never negative.
function retryAfterMs({ retryAfter, date }) { const seconds = Number(retryAfter); return Math.max(0, Number.isFinite(seconds) ? seconds * 1000 : Date.parse(retryAfter) - Date.parse(date)); }
Input & expected output
Input
{
"retryAfter": "30",
"date": "Wed, 28 Oct 2026 14:00:00 GMT"
}Expected output
30000The edge case
Input
{
"retryAfter": "Wed, 28 Oct 2026 14:00:30 GMT",
"date": "Wed, 28 Oct 2026 14:00:00 GMT"
}Expected output
30000Know the limits
- An HTTP date is compared with the response’s own Date header, not your clock, so clock skew cannot shorten the wait. The lab accepts delay-seconds from 0 to 86,400.
- Oveyon answers rate limiting with HTTP 429 and Retry-After. Wait at least this long, then retry with the same idempotency key.
The function above is the implementation used by the lab. The lab validates JSON types and caps size before execution; include equivalent validation when accepting untrusted input in your application.
Source & maintenance
Written by Oveyon for this edition of 1loc.dev; it is not part of the original collection. Copyright (c) 2026 Oveyon. MIT licensed.
The function above is the implementation the lab runs and the tests exercise. Read the license.
Keep exploring
- Convert an email domain to punycode — Keep the local part and convert an international domain to its ASCII xn-- form.
- Get the domain of an email address — Take the part after the last @ and lowercase it, for domain checks and grouping.
- Mask an email address for logs — Keep the first character and the domain; hide the rest of the local part.