diff --git a/src/OpenSearch/Handlers/SigV4Handler.php b/src/OpenSearch/Handlers/SigV4Handler.php index 5f37bf1d..f0a5b0ff 100644 --- a/src/OpenSearch/Handlers/SigV4Handler.php +++ b/src/OpenSearch/Handlers/SigV4Handler.php @@ -103,13 +103,17 @@ private function createRingRequest(RequestInterface $request, array $originalReq $body = null; } + // Reset the explicit port in the URL + $client = $originalRequest['client']; + unset($client['curl'][CURLOPT_PORT]); + $ringRequest = [ 'http_method' => $request->getMethod(), 'scheme' => $uri->getScheme(), 'uri' => $uri->getPath(), 'body' => $body, 'headers' => $request->getHeaders(), - 'client' => $originalRequest['client'] + 'client' => $client ]; if ($uri->getQuery()) { $ringRequest['query_string'] = $uri->getQuery(); diff --git a/tests/Handlers/SigV4HandlerTest.php b/tests/Handlers/SigV4HandlerTest.php index f3aa3691..418b05b2 100644 --- a/tests/Handlers/SigV4HandlerTest.php +++ b/tests/Handlers/SigV4HandlerTest.php @@ -68,9 +68,6 @@ public function testSignsRequestsTheSdkDefaultCredentialProviderChain() public function testSignsWithProvidedCredentials() { - $provider = CredentialProvider::fromCredentials( - new Credentials('foo', 'bar', 'baz') - ); $toWrap = function (array $ringRequest) { $this->assertArrayHasKey('X-Amz-Security-Token', $ringRequest['headers']); $this->assertSame('baz', $ringRequest['headers']['X-Amz-Security-Token'][0]); @@ -141,7 +138,7 @@ public function testClientParametersShouldBePassedToHandler() $this->assertArrayHasKey('client', $ringRequest); $this->assertArrayHasKey('timeout', $ringRequest['client']); $this->assertArrayHasKey('connect_timeout', $ringRequest['client']); - + return $this->getGenericResponse(); }; @@ -155,7 +152,25 @@ public function testClientParametersShouldBePassedToHandler() $client->indices()->exists(['index' => 'index']); } - private function getGenericResponse() + public function testClientPortDeterminedByURL() + { + $toWrap = function (array $ringRequest) { + $this->assertArrayNotHasKey(CURLOPT_PORT, $ringRequest['client']['curl']); + + return $this->getGenericResponse(); + }; + + $client = ClientBuilder::create() + ->setHandler($toWrap) + ->setHosts(['https://search--hgkaewb2ytci3t3y6yghh5m5vje.eu-central-1.es.amazonaws.com']) + ->setSigV4Region('us-west-2') + ->setSigV4CredentialProvider(new Credentials('foo', 'bar', 'baz')) + ->build(); + + $client->indices()->exists(['index' => 'index']); + } + + private function getGenericResponse(): CompletedFutureArray { return new CompletedFutureArray([ 'status' => 200,