Skip to content

Commit d3f4b84

Browse files
committed
[BUGFIX] Empty JSON-Content will be added to request
If you create an POST-Request (e.g. with an forking action) the HTTPClient will be created with a post content "[]". This can create some problems on requesting path. Solution: Check if the content is empty.
1 parent 3cb9b2c commit d3f4b84

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lib/Github/HttpClient/HttpClient.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,9 @@ public function request($path, array $parameters = array(), $httpMethod = 'GET',
167167

168168
$request = $this->createRequest($httpMethod, $path);
169169
$request->addHeaders($headers);
170-
$request->setContent(json_encode($parameters));
170+
if (count($parameters) > 0) {
171+
$request->setContent(json_encode($parameters));
172+
}
171173

172174
$hasListeners = 0 < count($this->listeners);
173175
if ($hasListeners) {

test/Github/Tests/HttpClient/HttpClientTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,23 @@ public function shouldDoPOSTRequest()
8484

8585
$httpClient = new HttpClient(array(), $client);
8686
$httpClient->post($path, $parameters, $headers);
87+
88+
$this->assertEquals('{"a":"b"}', $httpClient->getLastRequest()->getContent());
89+
}
90+
91+
/**
92+
* @test
93+
*/
94+
public function shouldDoPOSTRequestWithoutContent()
95+
{
96+
$path = '/some/path';
97+
98+
$client = $this->getBrowserMock();
99+
100+
$httpClient = new HttpClient(array(), $client);
101+
$httpClient->post($path);
102+
103+
$this->assertEmpty($httpClient->getLastRequest()->getContent());
87104
}
88105

89106
/**

0 commit comments

Comments
 (0)