Skip to content

Commit

Permalink
[11.x] Look for GuzzleHttp\ClientInterface first and make sure time…
Browse files Browse the repository at this point in the history
…outs and min TLS are applied when falling back (#47404)

* Look for `GuzzleHttp\ClientInterface` first and make sure timeouts and min TLS are applied when falling back

* formatting

* Update Event.php

---------

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
GrahamCampbell and taylorotwell authored Jun 18, 2023
1 parent 7d6a783 commit 55bd075
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/Illuminate/Console/Scheduling/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Closure;
use Cron\CronExpression;
use GuzzleHttp\Client as HttpClient;
use GuzzleHttp\ClientInterface as HttpClientInterface;
use GuzzleHttp\Exception\TransferException;
use Illuminate\Contracts\Container\Container;
use Illuminate\Contracts\Debug\ExceptionHandler;
Expand Down Expand Up @@ -597,15 +598,34 @@ public function pingOnFailure($url)
*/
protected function pingCallback($url)
{
return function (Container $container, HttpClient $http) use ($url) {
return function (Container $container) use ($url) {
try {
$http->request('GET', $url);
$this->getHttpClient($container)->request('GET', $url);
} catch (ClientExceptionInterface|TransferException $e) {
$container->make(ExceptionHandler::class)->report($e);
}
};
}

/**
* Get the Guzzle HTTP client to use to send pings.
*
* @param \Illuminate\Contracts\Container\Container $container
* @return \GuzzleHttp\ClientInterface
*/
protected function getHttpClient(Container $container)
{
return match (true) {
$container->bound(HttpClientInterface::class) => $container->make(HttpClientInterface::class),
$container->bound(HttpClient::class) => $container->make(HttpClient::class),
default => new HttpClient([
'connect_timeout' => 10,
'crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT,
'timeout' => 30,
]),
};
}

/**
* State that the command should run in the background.
*
Expand Down

0 comments on commit 55bd075

Please sign in to comment.