Skip to content

Commit

Permalink
Always set Guzzle base_uri (#1611) (#1618) (#1671)
Browse files Browse the repository at this point in the history
  • Loading branch information
reedy authored and ruflin committed Oct 16, 2019
1 parent 6ae6e16 commit 5a93853
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file based on the
### Backward Compatibility Breaks

### Bugfixes
* Always set the Guzzle `base_uri` to support connecting to multiple ES hosts. [#1618](https://github.com/ruflin/Elastica/pull/1618) [#1644](https://github.com/ruflin/Elastica/issues/1644)

### Added

Expand Down
7 changes: 1 addition & 6 deletions lib/Elastica/Transport/AwsAuthV4.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -15,18 +14,14 @@

class AwsAuthV4 extends Guzzle
{
protected function _getGuzzleClient($baseUrl, $persistent = true, Request $request)
protected function _getGuzzleClient($persistent = true)
{
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(),
],
]);
}

Expand Down
19 changes: 8 additions & 11 deletions lib/Elastica/Transport/Guzzle.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,13 @@ public function exec(Request $request, array $params)
{
$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()) {
Expand Down Expand Up @@ -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($baseUrl, $persistent = true, Request $request)
protected function _getGuzzleClient($persistent = true)
{
if (!$persistent || !self::$_guzzleClientConnection) {
self::$_guzzleClientConnection = new Client([
'base_uri' => $baseUrl,
'headers' => [
'Content-Type' => $request->getContentType(),
],
]);
self::$_guzzleClientConnection = new Client();
}

return self::$_guzzleClientConnection;
Expand Down

0 comments on commit 5a93853

Please sign in to comment.