From dc4a372b10b30dd5cae7da04ba6835cc926ef742 Mon Sep 17 00:00:00 2001 From: Nathan Baulch Date: Sun, 10 Mar 2019 11:32:11 +1100 Subject: [PATCH] Always set Guzzle base_uri (#1611) --- lib/Elastica/Transport/AwsAuthV4.php | 7 +------ lib/Elastica/Transport/Guzzle.php | 19 ++++++++----------- 2 files changed, 9 insertions(+), 17 deletions(-) mode change 100644 => 100755 lib/Elastica/Transport/AwsAuthV4.php mode change 100644 => 100755 lib/Elastica/Transport/Guzzle.php diff --git a/lib/Elastica/Transport/AwsAuthV4.php b/lib/Elastica/Transport/AwsAuthV4.php old mode 100644 new mode 100755 index fb4593dc25..72ba77589e --- a/lib/Elastica/Transport/AwsAuthV4.php +++ b/lib/Elastica/Transport/AwsAuthV4.php @@ -6,7 +6,6 @@ use Aws\Credentials\Credentials; use Aws\Signature\SignatureV4; use Elastica\Connection; -use Elastica\Request; use GuzzleHttp; use GuzzleHttp\Client; use GuzzleHttp\HandlerStack; @@ -15,18 +14,14 @@ class AwsAuthV4 extends Guzzle { - protected function _getGuzzleClient(string $baseUrl, bool $persistent = true, Request $request): Client + protected function _getGuzzleClient(bool $persistent = true): Client { if (!$persistent || !self::$_guzzleClientConnection) { $stack = HandlerStack::create(GuzzleHttp\choose_handler()); $stack->push($this->getSigningMiddleware(), 'sign'); self::$_guzzleClientConnection = new Client([ - 'base_uri' => $baseUrl, 'handler' => $stack, - 'headers' => [ - 'Content-Type' => $request->getContentType(), - ], ]); } diff --git a/lib/Elastica/Transport/Guzzle.php b/lib/Elastica/Transport/Guzzle.php old mode 100644 new mode 100755 index 920e19da60..4c25b5c3c8 --- a/lib/Elastica/Transport/Guzzle.php +++ b/lib/Elastica/Transport/Guzzle.php @@ -54,9 +54,13 @@ public function exec(Request $request, array $params): Response { $connection = $this->getConnection(); - $client = $this->_getGuzzleClient($this->_getBaseUrl($connection), $connection->isPersistent(), $request); + $client = $this->_getGuzzleClient($connection->isPersistent()); $options = [ + 'base_uri' => $this->_getBaseUrl($connection), + 'headers' => [ + 'Content-Type' => $request->getContentType(), + ], 'exceptions' => false, // 4xx and 5xx is expected and NOT an exceptions in this context ]; if ($connection->getTimeout()) { @@ -150,21 +154,14 @@ protected function _createPsr7Request(Request $request, Connection $connection) /** * Return Guzzle resource. * - * @param string $baseUrl - * @param bool $persistent False if not persistent connection - * @param Request $request Elastica Request Object + * @param bool $persistent False if not persistent connection * * @return Client */ - protected function _getGuzzleClient(string $baseUrl, bool $persistent = true, Request $request): Client + protected function _getGuzzleClient(bool $persistent = true): Client { if (!$persistent || !self::$_guzzleClientConnection) { - self::$_guzzleClientConnection = new Client([ - 'base_uri' => $baseUrl, - 'headers' => [ - 'Content-Type' => $request->getContentType(), - ], - ]); + self::$_guzzleClientConnection = new Client(); } return self::$_guzzleClientConnection;