Skip to content

feat(retry): enhance RetryMiddleware with Retry-After support and con…#3299

Open
rishi111-code wants to merge 1 commit intoguzzle:7.9from
rishi111-code:feat/retry-middleware
Open

feat(retry): enhance RetryMiddleware with Retry-After support and con…#3299
rishi111-code wants to merge 1 commit intoguzzle:7.9from
rishi111-code:feat/retry-middleware

Conversation

@rishi111-code
Copy link

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.

…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.
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