Skip to content

Commit

Permalink
Fix for #1064 reset custom headers (#1065)
Browse files Browse the repository at this point in the history
  • Loading branch information
ezimuel authored Sep 23, 2020
1 parent 0d89afb commit 1203ebd
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Elasticsearch/Connections/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,9 @@ public function performRequest(string $method, string $uri, ?array $params = [],
$body = $this->serializer->serialize($body);
}

$headers = $this->headers;
if (isset($options['client']['headers']) && is_array($options['client']['headers'])) {
$this->headers = array_merge($this->headers, $options['client']['headers']);
$headers = array_merge($this->headers, $options['client']['headers']);
}

$host = $this->host;
Expand All @@ -218,7 +219,7 @@ public function performRequest(string $method, string $uri, ?array $params = [],
[
'Host' => [$host]
],
$this->headers
$headers
)
];

Expand Down
29 changes: 29 additions & 0 deletions tests/Elasticsearch/Tests/Connections/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,4 +334,33 @@ function () {
$this->assertInstanceOf(ServerErrorResponseException::class, $result);
$this->assertContains('master_not_discovered_exception', $result->getMessage());
}

public function testHeaderClientParamIsResetAfterSent()
{
$host = [
'host' => 'localhost'
];

$connection = new Connection(
ClientBuilder::defaultHandler(),
$host,
[],
new SmartSerializer(),
$this->logger,
$this->trace
);

$options = [
'client' => [
'headers' => [
'Foo' => [ 'Bar' ]
]
]
];

$headersBefore = $connection->getHeaders();
$result = $connection->performRequest('GET', '/', null, null, $options);
$headersAfter = $connection->getHeaders();
$this->assertEquals($headersBefore, $headersAfter);
}
}

0 comments on commit 1203ebd

Please sign in to comment.