diff --git a/src/Illuminate/Http/Client/Factory.php b/src/Illuminate/Http/Client/Factory.php index 117d1115e2b1..c0d4888fcd0b 100644 --- a/src/Illuminate/Http/Client/Factory.php +++ b/src/Illuminate/Http/Client/Factory.php @@ -25,7 +25,7 @@ * @method \Illuminate\Http\Client\PendingRequest contentType(string $contentType) * @method \Illuminate\Http\Client\PendingRequest dd() * @method \Illuminate\Http\Client\PendingRequest dump() - * @method \Illuminate\Http\Client\PendingRequest retry(int $times, int $sleep = 0) + * @method \Illuminate\Http\Client\PendingRequest retry(int $times, int $sleep = 0, ?callable $when = null) * @method \Illuminate\Http\Client\PendingRequest sink(string|resource $to) * @method \Illuminate\Http\Client\PendingRequest stub(callable $callback) * @method \Illuminate\Http\Client\PendingRequest timeout(int $seconds) diff --git a/src/Illuminate/Http/Client/PendingRequest.php b/src/Illuminate/Http/Client/PendingRequest.php index b09113be0dca..d5426fb09cdd 100644 --- a/src/Illuminate/Http/Client/PendingRequest.php +++ b/src/Illuminate/Http/Client/PendingRequest.php @@ -98,6 +98,13 @@ class PendingRequest */ protected $retryDelay = 100; + /** + * The callback that will determine if the request should be retried. + * + * @var callable|null + */ + protected $retryWhenCallback = null; + /** * The callbacks that should execute before the request is sent. * @@ -441,12 +448,14 @@ public function timeout(int $seconds) * * @param int $times * @param int $sleep + * @param callable|null $when * @return $this */ - public function retry(int $times, int $sleep = 0) + public function retry(int $times, int $sleep = 0, ?callable $when = null) { $this->tries = $times; $this->retryDelay = $sleep; + $this->retryWhenCallback = $when; return $this; } @@ -679,7 +688,7 @@ public function send(string $method, string $url, array $options = []) throw new ConnectionException($e->getMessage(), 0, $e); } - }, $this->retryDelay ?? 100); + }, $this->retryDelay ?? 100, $this->retryWhenCallback); } /** diff --git a/src/Illuminate/Support/Facades/Http.php b/src/Illuminate/Support/Facades/Http.php index 21200c0a5aab..d6f2f6648578 100644 --- a/src/Illuminate/Support/Facades/Http.php +++ b/src/Illuminate/Support/Facades/Http.php @@ -20,7 +20,7 @@ * @method static \Illuminate\Http\Client\PendingRequest contentType(string $contentType) * @method static \Illuminate\Http\Client\PendingRequest dd() * @method static \Illuminate\Http\Client\PendingRequest dump() - * @method static \Illuminate\Http\Client\PendingRequest retry(int $times, int $sleep = 0) + * @method static \Illuminate\Http\Client\PendingRequest retry(int $times, int $sleep = 0, ?callable $when = null) * @method static \Illuminate\Http\Client\PendingRequest sink(string|resource $to) * @method static \Illuminate\Http\Client\PendingRequest stub(callable $callback) * @method static \Illuminate\Http\Client\PendingRequest timeout(int $seconds)