Skip to content

fix(client): parse Retry-After per RFC 9110 and never retry a cURL read source - #16

Merged
muhammetsafak merged 2 commits into
mainfrom
fix/retry-after-and-curl-infile-gate
Nov 27, 2026
Merged

muhammetsafak merged 2 commits into
mainfrom
fix/retry-after-and-curl-infile-gate

Conversation

@muhammetsafak

Copy link
Copy Markdown
Contributor

Summary

  • RetryAfter: delay-seconds is only ^\d+$; negative, fractional and relative values (-5, 1.5, tomorrow, now) return null and the client falls back to backoff. Previously -5 went to strtotime() and became about 18000 seconds.
  • All three HTTP-date formats (IMF-fixdate, RFC 850, asctime) are read as GMT, never in PHP's default time zone. Non-existent dates are rejected.
  • Client::sendRequest() sends a request once while curlOptions set CURLOPT_INFILE, CURLOPT_READFUNCTION or CURLOPT_READDATA: the first attempt consumes the read source, so a retry sent an empty body.
  • RetryPolicy docblock, docs/, README and CHANGELOG updated.

Test plan

  • vendor/bin/phpunit (592 tests, 1 pre-existing incomplete)
  • new tests fail on the old code and pass on the new (invalid values, asctime under Europe/Istanbul, INFILE/READFUNCTION/READDATA single attempt)
  • vendor/bin/phpstan analyse clean
  • wiki-sync.sh --check repos/HTTP/docs passes
  • CI matrix PHP 8.2-8.5 (php-cs-fixer does not run on the local PHP 8.6)

…ad source

Retry-After delay-seconds is now only ASCII digits, so -5 is no longer read as
a date offset and 1.5, tomorrow or now fall back to the backoff delay. The
IMF-fixdate, RFC 850 and asctime forms are all read as GMT instead of in PHP's
default time zone.

A request is also sent once while the client's cURL options set
CURLOPT_INFILE, CURLOPT_READFUNCTION or CURLOPT_READDATA, because the first
attempt consumes that read source and a retry would send an empty body.
DateTimeImmutable::createFromFormat() does not validate the D and l tokens, it
shifts the date to the next such weekday, so a wrong day name was read as a
date up to six days ahead. The day name is now captured and compared with the
parsed date, and the date is rejected on a mismatch.

The two-digit year of the RFC 850 form now follows the RFC 9110 50-year rule
instead of PHP's fixed 1970 pivot, which made the old rule dead code.
@muhammetsafak
muhammetsafak merged commit 0f56cc0 into main Nov 27, 2026
7 checks passed
@muhammetsafak
muhammetsafak deleted the fix/retry-after-and-curl-infile-gate branch November 27, 2026 05:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant