Skip to content

Commit

Permalink
Merge branch 'afrozenpeach-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
ezimuel committed Jun 13, 2019
2 parents e12e308 + 266bc0c commit 5a01a2b
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/Elasticsearch/ClientBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ private function normalizeExtendedHost(array $host): array
$host['scheme'] = 'http';
}
if (isset($host['port']) === false) {
$host['port'] = '9200';
$host['port'] = 9200;
}
return $host;
}
Expand Down
20 changes: 19 additions & 1 deletion src/Elasticsearch/Connections/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ class Connection implements ConnectionInterface
*/
protected $path;

/**
* @var int
*/
protected $port;

/**
* @var LoggerInterface
*/
Expand Down Expand Up @@ -129,6 +134,8 @@ public function __construct(
$connectionParams['client']['curl'][CURLOPT_USERPWD] = $hostDetails['user'].':'.$hostDetails['pass'];
}

$connectionParams['client']['curl'][CURLOPT_PORT] = $hostDetails['port'];

if (isset($connectionParams['client']['headers'])) {
$this->headers = $connectionParams['client']['headers'];
unset($connectionParams['client']['headers']);
Expand All @@ -143,13 +150,16 @@ public function __construct(
phpversion()
)];

$host = $hostDetails['host'].':'.$hostDetails['port'];
$host = $hostDetails['host'];
$path = null;
if (isset($hostDetails['path']) === true) {
$path = $hostDetails['path'];
}
$port = $hostDetails['port'];

$this->host = $host;
$this->path = $path;
$this->port = $port;
$this->log = $log;
$this->trace = $trace;
$this->connectionParams = $connectionParams;
Expand Down Expand Up @@ -494,6 +504,14 @@ public function getPath(): ?string
return $this->path;
}

/**
* @return int
*/
public function getPort()
{
return $this->port;
}

protected function getCurlRetryException(array $request, array $response): ElasticsearchException
{
$exception = null;
Expand Down
7 changes: 7 additions & 0 deletions src/Elasticsearch/Connections/ConnectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ public function getTransportSchema(): string;
*/
public function getHost(): string;

/**
* Get the port for this connection
*
* @return int
*/
public function getPort();

/**
* Get the username:password string for this connection, null if not set
*/
Expand Down
39 changes: 26 additions & 13 deletions tests/Elasticsearch/Tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,8 @@ public function testInlineHosts()
]
)->build();
$host = $client->transport->getConnection();
$this->assertSame("localhost:9200", $host->getHost());
$this->assertSame("localhost", $host->getHost());
$this->assertSame(9200, $host->getPort());
$this->assertSame("http", $host->getTransportSchema());


Expand All @@ -274,7 +275,8 @@ public function testInlineHosts()
]
)->build();
$host = $client->transport->getConnection();
$this->assertSame("localhost:9200", $host->getHost());
$this->assertSame("localhost", $host->getHost());
$this->assertSame(9200, $host->getPort());
$this->assertSame("http", $host->getTransportSchema());

$client = Elasticsearch\ClientBuilder::create()->setHosts(
Expand All @@ -283,7 +285,8 @@ public function testInlineHosts()
]
)->build();
$host = $client->transport->getConnection();
$this->assertSame("foo.com:9200", $host->getHost());
$this->assertSame("foo.com", $host->getHost());
$this->assertSame(9200, $host->getPort());
$this->assertSame("http", $host->getTransportSchema());

$client = Elasticsearch\ClientBuilder::create()->setHosts(
Expand All @@ -292,7 +295,8 @@ public function testInlineHosts()
]
)->build();
$host = $client->transport->getConnection();
$this->assertSame("foo.com:9200", $host->getHost());
$this->assertSame("foo.com", $host->getHost());
$this->assertSame(9200, $host->getPort());
$this->assertSame("https", $host->getTransportSchema());


Expand All @@ -302,7 +306,8 @@ public function testInlineHosts()
]
)->build();
$host = $client->transport->getConnection();
$this->assertSame("foo.com:9200", $host->getHost());
$this->assertSame("foo.com", $host->getHost());
$this->assertSame(9200, $host->getPort());
$this->assertSame("https", $host->getTransportSchema());
$this->assertSame("user:pass", $host->getUserPass());
}
Expand All @@ -319,7 +324,8 @@ public function testExtendedHosts()
]
)->build();
$host = $client->transport->getConnection();
$this->assertSame("localhost:9200", $host->getHost());
$this->assertSame("localhost", $host->getHost());
$this->assertSame(9200, $host->getPort());
$this->assertSame("http", $host->getTransportSchema());


Expand All @@ -333,7 +339,8 @@ public function testExtendedHosts()
]
)->build();
$host = $client->transport->getConnection();
$this->assertSame("foo.com:9200", $host->getHost());
$this->assertSame("foo.com", $host->getHost());
$this->assertSame(9200, $host->getPort());
$this->assertSame("http", $host->getTransportSchema());


Expand All @@ -347,7 +354,8 @@ public function testExtendedHosts()
]
)->build();
$host = $client->transport->getConnection();
$this->assertSame("foo.com:9200", $host->getHost());
$this->assertSame("foo.com", $host->getHost());
$this->assertSame(9200, $host->getPort());
$this->assertSame("https", $host->getTransportSchema());


Expand All @@ -360,7 +368,8 @@ public function testExtendedHosts()
]
)->build();
$host = $client->transport->getConnection();
$this->assertSame("foo.com:9200", $host->getHost());
$this->assertSame("foo.com", $host->getHost());
$this->assertSame(9200, $host->getPort());
$this->assertSame("http", $host->getTransportSchema());


Expand All @@ -372,7 +381,8 @@ public function testExtendedHosts()
]
)->build();
$host = $client->transport->getConnection();
$this->assertSame("foo.com:9200", $host->getHost());
$this->assertSame("foo.com", $host->getHost());
$this->assertSame(9200, $host->getPort());
$this->assertSame("http", $host->getTransportSchema());


Expand All @@ -386,7 +396,8 @@ public function testExtendedHosts()
]
)->build();
$host = $client->transport->getConnection();
$this->assertSame("foo.com:9500", $host->getHost());
$this->assertSame("foo.com", $host->getHost());
$this->assertSame(9500, $host->getPort());
$this->assertSame("https", $host->getTransportSchema());


Expand All @@ -413,7 +424,8 @@ public function testExtendedHosts()
]
)->build();
$host = $client->transport->getConnection();
$this->assertSame("the_foo.com:9200", $host->getHost());
$this->assertSame("the_foo.com", $host->getHost());
$this->assertSame(9200, $host->getPort());
$this->assertSame("http", $host->getTransportSchema());


Expand All @@ -428,7 +440,8 @@ public function testExtendedHosts()
]
)->build();
$host = $client->transport->getConnection();
$this->assertSame("foo.com:9200", $host->getHost());
$this->assertSame("foo.com", $host->getHost());
$this->assertSame(9200, $host->getPort());
$this->assertSame("http", $host->getTransportSchema());
$this->assertSame("user:abc#$@?%!abc", $host->getUserPass());
}
Expand Down

0 comments on commit 5a01a2b

Please sign in to comment.