Skip to content

Commit be18a9e

Browse files
emmetogNyholm
authored andcommitted
Bugfix: headers not being passed to request (#529)
* Add IDE files to gitignore * Add failing UT to show bug * Fix bug: reset plugin when headers change * Remove IDEs from gitignore
1 parent 6a78d56 commit be18a9e

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

Diff for: lib/Github/HttpClient/Builder.php

+3
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ public function addHeaderValue($header, $headerValue)
168168
} else {
169169
$this->headers[$header] = array_merge((array)$this->headers[$header], array($headerValue));
170170
}
171+
172+
$this->removePlugin(Plugin\HeaderAppendPlugin::class);
173+
$this->addPlugin(new Plugin\HeaderAppendPlugin($this->headers));
171174
}
172175

173176
/**

Diff for: test/Github/Tests/HttpClient/BuilderTest.php

+24
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,28 @@ public function shouldAddHeaders()
4949

5050
$client->addHeaders($headers);
5151
}
52+
53+
/**
54+
* @test
55+
*/
56+
public function appendingHeaderShouldAddAndRemovePlugin()
57+
{
58+
$expectedHeaders = [
59+
'Accept' => 'application/vnd.github.v3',
60+
];
61+
62+
$client = $this->getMockBuilder(\Github\HttpClient\Builder::class)
63+
->setMethods(array('removePlugin', 'addPlugin'))
64+
->getMock();
65+
66+
$client->expects($this->once())
67+
->method('removePlugin')
68+
->with(Plugin\HeaderAppendPlugin::class);
69+
70+
$client->expects($this->once())
71+
->method('addPlugin')
72+
->with(new Plugin\HeaderAppendPlugin($expectedHeaders));
73+
74+
$client->addHeaderValue('Accept', 'application/vnd.github.v3');
75+
}
5276
}

0 commit comments

Comments
 (0)