Skip to content

Commit 5a93853

Browse files
reedyruflin
authored andcommitted
Always set Guzzle base_uri (#1611) (#1618) (#1671)
1 parent 6ae6e16 commit 5a93853

File tree

3 files changed

+10
-17
lines changed

3 files changed

+10
-17
lines changed

CHANGELOG.md

100644100755
+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file based on the
66
### Backward Compatibility Breaks
77

88
### Bugfixes
9+
* 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)
910

1011
### Added
1112

lib/Elastica/Transport/AwsAuthV4.php

100644100755
+1-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use Aws\Credentials\Credentials;
77
use Aws\Signature\SignatureV4;
88
use Elastica\Connection;
9-
use Elastica\Request;
109
use GuzzleHttp;
1110
use GuzzleHttp\Client;
1211
use GuzzleHttp\HandlerStack;
@@ -15,18 +14,14 @@
1514

1615
class AwsAuthV4 extends Guzzle
1716
{
18-
protected function _getGuzzleClient($baseUrl, $persistent = true, Request $request)
17+
protected function _getGuzzleClient($persistent = true)
1918
{
2019
if (!$persistent || !self::$_guzzleClientConnection) {
2120
$stack = HandlerStack::create(GuzzleHttp\choose_handler());
2221
$stack->push($this->getSigningMiddleware(), 'sign');
2322

2423
self::$_guzzleClientConnection = new Client([
25-
'base_uri' => $baseUrl,
2624
'handler' => $stack,
27-
'headers' => [
28-
'Content-Type' => $request->getContentType(),
29-
],
3025
]);
3126
}
3227

lib/Elastica/Transport/Guzzle.php

100644100755
+8-11
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,13 @@ public function exec(Request $request, array $params)
5454
{
5555
$connection = $this->getConnection();
5656

57-
$client = $this->_getGuzzleClient($this->_getBaseUrl($connection), $connection->isPersistent(), $request);
57+
$client = $this->_getGuzzleClient($connection->isPersistent());
5858

5959
$options = [
60+
'base_uri' => $this->_getBaseUrl($connection),
61+
'headers' => [
62+
'Content-Type' => $request->getContentType(),
63+
],
6064
'exceptions' => false, // 4xx and 5xx is expected and NOT an exceptions in this context
6165
];
6266
if ($connection->getTimeout()) {
@@ -150,21 +154,14 @@ protected function _createPsr7Request(Request $request, Connection $connection)
150154
/**
151155
* Return Guzzle resource.
152156
*
153-
* @param string $baseUrl
154-
* @param bool $persistent False if not persistent connection
155-
* @param Request $request Elastica Request Object
157+
* @param bool $persistent False if not persistent connection
156158
*
157159
* @return Client
158160
*/
159-
protected function _getGuzzleClient($baseUrl, $persistent = true, Request $request)
161+
protected function _getGuzzleClient($persistent = true)
160162
{
161163
if (!$persistent || !self::$_guzzleClientConnection) {
162-
self::$_guzzleClientConnection = new Client([
163-
'base_uri' => $baseUrl,
164-
'headers' => [
165-
'Content-Type' => $request->getContentType(),
166-
],
167-
]);
164+
self::$_guzzleClientConnection = new Client();
168165
}
169166

170167
return self::$_guzzleClientConnection;

0 commit comments

Comments
 (0)