From 55bd0753fbeb0e36a908ddbd1683ee30eab8952c Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sun, 18 Jun 2023 20:05:02 +0100 Subject: [PATCH] [11.x] Look for `GuzzleHttp\ClientInterface` first and make sure timeouts 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 --- src/Illuminate/Console/Scheduling/Event.php | 24 +++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Console/Scheduling/Event.php b/src/Illuminate/Console/Scheduling/Event.php index 0ff10188b251..9ff1fa867c42 100644 --- a/src/Illuminate/Console/Scheduling/Event.php +++ b/src/Illuminate/Console/Scheduling/Event.php @@ -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; @@ -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. *