Skip to content

Commit e8f0f7b

Browse files
committed
The default port 80 and 443 are not removed if includePortInHostHeader is true
1 parent c193338 commit e8f0f7b

File tree

2 files changed

+6
-18
lines changed

2 files changed

+6
-18
lines changed

src/Elasticsearch/Connections/Connection.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,7 @@ public function performRequest(string $method, string $uri, ?array $params = [],
200200

201201
$host = $this->host;
202202
if (isset($this->connectionParams['client']['port_in_header']) && $this->connectionParams['client']['port_in_header']) {
203-
if (!in_array((int) $this->port, [80,443])) {
204-
$host .= ':' . $this->port;
205-
}
203+
$host .= ':' . $this->port;
206204
}
207205

208206
$request = [

tests/Elasticsearch/Tests/ClientBuilderTest.php

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -71,23 +71,13 @@ public function testElasticCloudIdNotOverrideCurlEncoding()
7171
}
7272
}
7373

74-
public function getHttpPorts()
75-
{
76-
return [
77-
[ 80, false ], // not included since 80 is standard port for HTTP
78-
[ 443, false ], // not included since 442 is standard port for HTTPS
79-
[ 1234, true ] // included since 1234 is not a standard port
80-
];
81-
}
82-
8374
/**
84-
* @dataProvider getHttpPorts
8575
* @see https://github.com/elastic/elasticsearch-php/issues/993
8676
*/
87-
public function testIncludePortInHostHeader(int $port, bool $included)
77+
public function testIncludePortInHostHeader()
8878
{
8979
$host = "localhost";
90-
$url = "localhost:$port";
80+
$url = "$host:1234";
9181
$params = [
9282
'client' => [
9383
'verbose' => true
@@ -106,14 +96,14 @@ public function testIncludePortInHostHeader(int $port, bool $included)
10696
} catch (ElasticsearchException $e) {
10797
$request = $client->transport->getLastConnection()->getLastRequestInfo();
10898
$this->assertTrue(isset($request['request']['headers']['Host'][0]));
109-
$this->assertEquals($included ? $url : $host, $request['request']['headers']['Host'][0]);
99+
$this->assertEquals($url, $request['request']['headers']['Host'][0]);
110100
}
111101
}
112102

113103
/**
114104
* @see https://github.com/elastic/elasticsearch-php/issues/993
115105
*/
116-
public function testNotIncludeStandardPortInHostHeaderAsDefault()
106+
public function testNotIncludePortInHostHeaderAsDefault()
117107
{
118108
$host = "localhost";
119109
$url = "$host:1234";
@@ -141,7 +131,7 @@ public function testNotIncludeStandardPortInHostHeaderAsDefault()
141131
/**
142132
* @see https://github.com/elastic/elasticsearch-php/issues/993
143133
*/
144-
public function testNotIncludeStandardPortInHostHeader()
134+
public function testNotIncludePortInHostHeader()
145135
{
146136
$host = "localhost";
147137
$url = "$host:1234";

0 commit comments

Comments
 (0)