feat(retry): rate-limit aware retries and RateLimit header parsing - #905
feat(retry): rate-limit aware retries and RateLimit header parsing#905Naoray wants to merge 3 commits into
Conversation
| return null; | ||
| } | ||
|
|
||
| $segments = array_map('trim', explode(';', $header)); |
There was a problem hiding this comment.
Blocking: this is the pre-hardening parser rather than the behavior already merged on the v4 line. Response::header() uses PSR-7 getHeaderLine(), so multiple field values arrive comma-joined. This parser treats the complete value as one policy and returns null for valid inputs such as "get-v2-refunds";r=3, "get-v2-payments";r=7 paired with "post-v2-payments";q=5, "get-v2-payments";q=20.
There is a second omitted hardening in src/Http/ExponentialRetryStrategy.php:69: the exponential value is cast to int before it is capped, so delayBeforeAttemptMs(PHP_INT_MAX) returns 0 instead of maxDelayMs.
Please port PHP 7.4-compatible versions of the merged v4 list splitting/policy matching and finite/capped exponential calculation, together with their regression tests.
This backport adds response header accessors and parsed rate-limit metadata, exposes Retry-After delays through TooManyRequestsException without changing its inherited positional constructor behavior, and introduces an opt-in exponential retry strategy with jitter and a configurable delay budget. The default linear strategy continues to retry temporary network failures as before.
RetryStrategyContract and LinearRetryStrategy remain byte-for-byte identical to v3.13.1, so existing implementations and subclasses continue to load unchanged. Strategies that need exception-aware decisions, including HTTP 429 handling, can opt into ConditionalRetryStrategyContract, which extends the existing contract without adding requirements to legacy implementations.
The backport retains PHP 7.4 compatibility by using explicit properties and constructors instead of constructor property promotion, avoiding newer syntax, and parsing rate-limit dates with the platform DateTimeImmutable API.