From d3f4b848cf12f5ed8bf63d6a4aa5634f68884af1 Mon Sep 17 00:00:00 2001 From: Andy Grunwald Date: Sat, 2 Mar 2013 09:49:05 +0100 Subject: [PATCH] [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. --- lib/Github/HttpClient/HttpClient.php | 4 +++- test/Github/Tests/HttpClient/HttpClientTest.php | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) 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()); } /**