Skip to content

Commit

Permalink
Loosen up php and dependency version constraints to allow a broader u…
Browse files Browse the repository at this point in the history
…sage of this package
  • Loading branch information
TheLevti committed Nov 5, 2022
1 parent 301e0f4 commit b5ea560
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 72 deletions.
11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ The format is based on [Keep a Changelog][1], and this project adheres to

## [Unreleased]

## [1.1.0] - 2022-11-05

### Changed

- Loosen up php and dependency version constraints to allow a broader usage of this package.

## [1.0.1] - 2022-11-05

### Added
Expand All @@ -31,6 +37,7 @@ The format is based on [Keep a Changelog][1], and this project adheres to
[1]: https://keepachangelog.com/en/1.1.0/
[2]: https://semver.org/spec/v2.0.0.html

[Unreleased]: https://github.com/Poor-Plebs/guzzle-retry-after-middleware/compare/1.0.1...HEAD
[1.0.0]: https://github.com/Poor-Plebs/guzzle-retry-after-middleware/releases/1.0.1
[Unreleased]: https://github.com/Poor-Plebs/guzzle-retry-after-middleware/compare/1.1.0...HEAD
[1.1.0]: https://github.com/Poor-Plebs/guzzle-retry-after-middleware/releases/1.1.0
[1.0.1]: https://github.com/Poor-Plebs/guzzle-retry-after-middleware/releases/1.0.1
[1.0.0]: https://github.com/Poor-Plebs/guzzle-retry-after-middleware/releases/1.0.0
11 changes: 5 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,12 @@
"roave/security-advisories": "dev-latest"
},
"require": {
"php": "^8.1.0",
"guzzlehttp/guzzle": "^7.5.0",
"guzzlehttp/promises": "^1.5.0",
"nesbot/carbon": "^2.62.0",
"php": "^8.0.0",
"guzzlehttp/guzzle": "^6.5.8 || ^7.4.5",
"guzzlehttp/promises": "^1.0.0",
"nesbot/carbon": "^2.0.0",
"psr/http-message": "^1.0.0",
"psr/log": "^3.0.0",
"psr/simple-cache": "^3.0.0"
"psr/simple-cache": "^1.0.0 || ^2.0.0 || ^3.0.0"
},
"scripts": {
"all": [
Expand Down
118 changes: 59 additions & 59 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 10 additions & 5 deletions src/RetryAfterMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@
use Carbon\CarbonImmutable;
use Carbon\CarbonInterface;
use GuzzleHttp\Exception\BadResponseException;
use GuzzleHttp\Promise\Create;
use GuzzleHttp\Promise\PromiseInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\SimpleCache\CacheInterface;
use Throwable;

use function GuzzleHttp\Promise\rejection_for;

class RetryAfterMiddleware
{
private const HEADER = 'Retry-After';

public function __construct(protected readonly CacheInterface $cache)
public function __construct(protected CacheInterface $cache)
{
}

Expand All @@ -33,7 +34,7 @@ public function __invoke(string $key): callable

$now = new CarbonImmutable();
if ($retryAfter->greaterThanOrEqualTo($now)) {
return Create::rejectionFor(new RetryAfterException(
return rejection_for(new RetryAfterException(
$this->retryAfterMessage($retryAfter, $now),
$request,
));
Expand All @@ -48,10 +49,14 @@ function (ResponseInterface $response) use ($key): mixed {
},
function (Throwable $reason) use ($key): PromiseInterface {
if ($reason instanceof BadResponseException) {
$this->checkHeader($reason->getResponse(), $key);
$response = $reason->getResponse();

if ($response instanceof ResponseInterface) {
$this->checkHeader($response, $key);
}
}

return Create::rejectionFor($reason);
return rejection_for($reason);
}
);
};
Expand Down

0 comments on commit b5ea560

Please sign in to comment.