diff --git a/lib/Github/HttpClient/HttpClient.php b/lib/Github/HttpClient/HttpClient.php index bd402e17087..8b84fc3ec47 100644 --- a/lib/Github/HttpClient/HttpClient.php +++ b/lib/Github/HttpClient/HttpClient.php @@ -167,7 +167,9 @@ public function request($path, array $parameters = array(), $httpMethod = 'GET', $request = $this->createRequest($httpMethod, $path); $request->addHeaders($headers); - $request->setContent(json_encode($parameters)); + if (count($parameters) > 0) { + $request->setContent(json_encode($parameters)); + } $hasListeners = 0 < count($this->listeners); if ($hasListeners) { diff --git a/test/Github/Tests/HttpClient/HttpClientTest.php b/test/Github/Tests/HttpClient/HttpClientTest.php index 164a33506ca..4fc44717537 100644 --- a/test/Github/Tests/HttpClient/HttpClientTest.php +++ b/test/Github/Tests/HttpClient/HttpClientTest.php @@ -84,6 +84,23 @@ public function shouldDoPOSTRequest() $httpClient = new HttpClient(array(), $client); $httpClient->post($path, $parameters, $headers); + + $this->assertEquals('{"a":"b"}', $httpClient->getLastRequest()->getContent()); + } + + /** + * @test + */ + public function shouldDoPOSTRequestWithoutContent() + { + $path = '/some/path'; + + $client = $this->getBrowserMock(); + + $httpClient = new HttpClient(array(), $client); + $httpClient->post($path); + + $this->assertEmpty($httpClient->getLastRequest()->getContent()); } /**