Skip to content

feat(http/unstable): add parseRetryAfter - #7299

Open
tomas-zijdemans wants to merge 1 commit into
denoland:mainfrom
tomas-zijdemans:retry-after-parser
Open

feat(http/unstable): add parseRetryAfter#7299
tomas-zijdemans wants to merge 1 commit into
denoland:mainfrom
tomas-zijdemans:retry-after-parser

Conversation

@tomas-zijdemans

@tomas-zijdemans tomas-zijdemans commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Adds parseRetryAfter to @std/http as an unstable API. It turns a Retry-After header value into milliseconds to wait, so a retry loop after a 429 or 503 can honor the server instead of guessing.

Implements the parser half of #7296. The predicate half is #7298.

What it does

  • Accepts delta-seconds and all three RFC 9110 HTTP-date forms: IMF-fixdate, RFC 850, and asctime.
  • Returns milliseconds from now, clamped to 0 for past dates. Returns null for anything invalid. Never throws.
  • Skips Date.parse on purpose: it accepts junk like "-1" and " 120" and silently normalizes invalid calendar dates. Each grammar is matched exactly, with calendar and weekday validation.

Worth a close look

  • The RFC 850 two-digit-year rule: a timestamp more than 50 years in the future resolves to the most recent past year with the same final two digits (RFC 9110 5.6.7).
  • Leap seconds: second 60 normalizes to the following instant, since JS Date cannot represent it.
  • Overflow: delta-seconds convert only when the millisecond result is a safe integer.

Scope

This PR only parses the field. Emitting Retry-After belongs to the server-side rate-limiting work in #7237. Honoring it inside @std/async retry() is a separate upcoming proposal. Nothing here touches @std/async.

Testing

23 tests with fixed now values and GMT dates: all three date forms, both sides of the 50-year boundary, a leap second, overflow, and a pile of near-miss syntax. deno task ok and the Node cross-runtime runner pass.

@github-actions github-actions Bot added the http label Aug 23, 2026
@codecov

codecov Bot commented Aug 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.05%. Comparing base (ca58f94) to head (3ab4731).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7299      +/-   ##
==========================================
+ Coverage   95.03%   95.05%   +0.01%     
==========================================
  Files         617      619       +2     
  Lines       51637    52030     +393     
  Branches     9359     9431      +72     
==========================================
+ Hits        49075    49455     +380     
- Misses       2021     2030       +9     
- Partials      541      545       +4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant