Skip to content

Commit 1203ebd

Browse files
authored
Fix for #1064 reset custom headers (#1065)
1 parent 0d89afb commit 1203ebd

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

src/Elasticsearch/Connections/Connection.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,9 @@ public function performRequest(string $method, string $uri, ?array $params = [],
200200
$body = $this->serializer->serialize($body);
201201
}
202202

203+
$headers = $this->headers;
203204
if (isset($options['client']['headers']) && is_array($options['client']['headers'])) {
204-
$this->headers = array_merge($this->headers, $options['client']['headers']);
205+
$headers = array_merge($this->headers, $options['client']['headers']);
205206
}
206207

207208
$host = $this->host;
@@ -218,7 +219,7 @@ public function performRequest(string $method, string $uri, ?array $params = [],
218219
[
219220
'Host' => [$host]
220221
],
221-
$this->headers
222+
$headers
222223
)
223224
];
224225

tests/Elasticsearch/Tests/Connections/ConnectionTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,4 +334,33 @@ function () {
334334
$this->assertInstanceOf(ServerErrorResponseException::class, $result);
335335
$this->assertContains('master_not_discovered_exception', $result->getMessage());
336336
}
337+
338+
public function testHeaderClientParamIsResetAfterSent()
339+
{
340+
$host = [
341+
'host' => 'localhost'
342+
];
343+
344+
$connection = new Connection(
345+
ClientBuilder::defaultHandler(),
346+
$host,
347+
[],
348+
new SmartSerializer(),
349+
$this->logger,
350+
$this->trace
351+
);
352+
353+
$options = [
354+
'client' => [
355+
'headers' => [
356+
'Foo' => [ 'Bar' ]
357+
]
358+
]
359+
];
360+
361+
$headersBefore = $connection->getHeaders();
362+
$result = $connection->performRequest('GET', '/', null, null, $options);
363+
$headersAfter = $connection->getHeaders();
364+
$this->assertEquals($headersBefore, $headersAfter);
365+
}
337366
}

0 commit comments

Comments
 (0)