Skip to content

feat(client)!: retry only idempotent methods by default and make retries safer - #14

Merged
muhammetsafak merged 2 commits into
mainfrom
feat/retry-safe-defaults
Nov 24, 2026
Merged

muhammetsafak merged 2 commits into
mainfrom
feat/retry-safe-defaults

Conversation

@muhammetsafak

Copy link
Copy Markdown
Contributor

Summary

  • RetryPolicy retries only idempotent methods by default (RFC 9110 section 9.2.2: GET, HEAD, OPTIONS, TRACE, PUT, DELETE). POST and PATCH are sent once unless listed in the new, last constructor argument retryableMethods. Breaking.
  • Retry-After is capped at maxDelay (a server could previously make the client wait an hour).
  • A request whose body is not seekable is sent once. Verified first with a test against the real cURL transport: the retry sent an empty body, because the first attempt had consumed the stream. The first response is now returned, or the first exception thrown.
  • Docs (Client-Retry, Client-Configuration, README) and CHANGELOG.md [Unreleased] updated.

Test plan

  • composer validate --strict
  • vendor/bin/php-cs-fixer fix --dry-run --diff
  • vendor/bin/phpstan analyse --memory-limit=512M
  • vendor/bin/phpunit (new unit tests plus end-to-end tests against the fixture server)
  • wiki-sync.sh --check rc=0

…ies safer

RetryPolicy now retries only GET, HEAD, OPTIONS, TRACE, PUT and DELETE
(RFC 9110 section 9.2.2) unless retryableMethods says otherwise. The new
constructor argument is appended last, so existing positional calls keep
working.

Retry-After is capped at maxDelay, and a request whose body is not
seekable is sent once: a retry used to send an empty body because the
first attempt had already consumed the stream.
Reading the method or body of a request while deciding whether it may be
replayed could leak a raw exception when a policy was attached; such a
request is now sent once and fails as a RequestException, as without a
policy. Also document that maxDelay caps Retry-After in the RetryPolicy
docblocks, correct the CHANGELOG migration recipe and the README comment.
@muhammetsafak
muhammetsafak merged commit 00df3e0 into main Nov 24, 2026
7 checks passed
@muhammetsafak
muhammetsafak deleted the feat/retry-safe-defaults branch November 24, 2026 06:59
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