From 658069b1299fde1007e866e3afd741b1cb55c22a Mon Sep 17 00:00:00 2001 From: Craig Ballinger Date: Thu, 2 Sep 2021 10:10:50 -0400 Subject: [PATCH] [8.x] Return a new or existing guzzle client based on context (#38642) * Return a new or existing guzzle client based on context * StyleCI fixes * Update PendingRequest.php Co-authored-by: Taylor Otwell --- src/Illuminate/Http/Client/PendingRequest.php | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/Illuminate/Http/Client/PendingRequest.php b/src/Illuminate/Http/Client/PendingRequest.php index d5426fb09cdd..40a3a8755753 100644 --- a/src/Illuminate/Http/Client/PendingRequest.php +++ b/src/Illuminate/Http/Client/PendingRequest.php @@ -798,6 +798,28 @@ protected function populateResponse(Response $response) * @return \GuzzleHttp\Client */ public function buildClient() + { + return $this->requestsReusableClient() + ? $this->getReusableClient() + : $this->createClient($this->buildHandlerStack()); + } + + /** + * Determine if a reusable client is required. + * + * @return bool + */ + protected function requestsReusableClient() + { + return ! is_null($this->client) || $this->async; + } + + /** + * Retrieve a reusable Guzzle client. + * + * @return \GuzzleHttp\Client + */ + protected function getReusableClient() { return $this->client = $this->client ?: $this->createClient($this->buildHandlerStack()); }