feat(retry): enhance RetryMiddleware with Retry-After support and con…#3299
Open
rishi111-code wants to merge 1 commit intoguzzle:7.9from
Open
feat(retry): enhance RetryMiddleware with Retry-After support and con…#3299rishi111-code wants to merge 1 commit intoguzzle:7.9from
rishi111-code wants to merge 1 commit intoguzzle:7.9from
Conversation
…figurable backoff Enhances RetryMiddleware in Guzzle HTTP client to support rate-limit awareness and customizable retry logic: Recognizes and honors the Retry-After header (numeric and HTTP-date formats) for accurate wait times. Adds configurable maxRetries and baseDelay (in ms) for exponential backoff control. Retains existing support for connection errors and server (5xx/429) retries. Why It Matters This upgrade delivers smarter and more resilient HTTP clients: Adapts to server-imposed delays (Retry-After), reducing unnecessary retries. Offers flexible defaults — maxRetries = 3, baseDelay = 100 ms — while allowing overrides. Reduces boilerplate: developers no longer need to build custom retry logic from scratch. Key Changes Modified src/RetryMiddleware.php: Introduced maxRetries and baseDelay parameters. Enhanced __invoke() flow to parse Retry-After header and implement delay logic. Ensured delay continues via exponential backoff when Retry-After isn’t present. Updated tests/RetryMiddlewareTest.php: Added new test testRespectsRetryAfterHeader to validate Retry-After handling. Ensured retries occur as expected when the header exists. Test Coverage Includes existing and new tests verifying: Default retry behavior on connection failures and server errors. Correct delay and retry count in exponential backoff scenarios. Respect for Retry-After, ensuring the middleware waits properly before retrying. Compatibility Fully backward-compatible. No breaking changes—just enhancements layered onto existing behavior.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Enhances RetryMiddleware in Guzzle HTTP client to support rate-limit awareness and customizable retry logic:
Recognizes and honors the Retry-After header (numeric and HTTP-date formats) for accurate wait times.
Adds configurable maxRetries and baseDelay (in ms) for exponential backoff control.
Retains existing support for connection errors and server (5xx/429) retries.
Why It Matters
This upgrade delivers smarter and more resilient HTTP clients:
Adapts to server-imposed delays (Retry-After), reducing unnecessary retries.
Offers flexible defaults — maxRetries = 3, baseDelay = 100 ms — while allowing overrides.
Reduces boilerplate: developers no longer need to build custom retry logic from scratch.
Key Changes
Modified src/RetryMiddleware.php:
Introduced maxRetries and baseDelay parameters.
Enhanced __invoke() flow to parse Retry-After header and implement delay logic.
Ensured delay continues via exponential backoff when Retry-After isn’t present.
Updated tests/RetryMiddlewareTest.php:
Added new test testRespectsRetryAfterHeader to validate Retry-After handling.
Ensured retries occur as expected when the header exists.
Test Coverage
Includes existing and new tests verifying:
Default retry behavior on connection failures and server errors.
Correct delay and retry count in exponential backoff scenarios.
Respect for Retry-After, ensuring the middleware waits properly before retrying.
Compatibility
Fully backward-compatible. No breaking changes—just enhancements layered onto existing behavior.