diff --git a/lib/Github/HttpClient/Builder.php b/lib/Github/HttpClient/Builder.php index 7d2052498e6..5b742285bd9 100644 --- a/lib/Github/HttpClient/Builder.php +++ b/lib/Github/HttpClient/Builder.php @@ -168,6 +168,9 @@ public function addHeaderValue($header, $headerValue) } else { $this->headers[$header] = array_merge((array)$this->headers[$header], array($headerValue)); } + + $this->removePlugin(Plugin\HeaderAppendPlugin::class); + $this->addPlugin(new Plugin\HeaderAppendPlugin($this->headers)); } /** diff --git a/test/Github/Tests/HttpClient/BuilderTest.php b/test/Github/Tests/HttpClient/BuilderTest.php index 3643dd292fa..dadfd4f44d8 100644 --- a/test/Github/Tests/HttpClient/BuilderTest.php +++ b/test/Github/Tests/HttpClient/BuilderTest.php @@ -49,4 +49,28 @@ public function shouldAddHeaders() $client->addHeaders($headers); } + + /** + * @test + */ + public function appendingHeaderShouldAddAndRemovePlugin() + { + $expectedHeaders = [ + 'Accept' => 'application/vnd.github.v3', + ]; + + $client = $this->getMockBuilder(\Github\HttpClient\Builder::class) + ->setMethods(array('removePlugin', 'addPlugin')) + ->getMock(); + + $client->expects($this->once()) + ->method('removePlugin') + ->with(Plugin\HeaderAppendPlugin::class); + + $client->expects($this->once()) + ->method('addPlugin') + ->with(new Plugin\HeaderAppendPlugin($expectedHeaders)); + + $client->addHeaderValue('Accept', 'application/vnd.github.v3'); + } }