Skip to content

Commit 54a3dd5

Browse files
committed
Fix php-curl-class#53: Return response body when calling HTTP request methods
1 parent 85e4109 commit 54a3dd5

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

src/Curl/Curl.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ protected function exec($_ch = null)
433433

434434
$ch->call($this->complete_function, $ch);
435435

436-
return $ch->error_code;
436+
return $ch->response;
437437
}
438438

439439
private function call($function)

tests/PHPCurlClass/PHPCurlClassTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,15 @@ public function testReferrer()
305305
)) === 'myreferrer');
306306
}
307307

308+
public function testResponseBody()
309+
{
310+
foreach (array('GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS') as $request_method) {
311+
$curl = new Curl();
312+
$curl->setHeader('X-DEBUG-TEST', 'response_body');
313+
$this->assertTrue($curl->$request_method(Test::TEST_URL) === 'OK');
314+
}
315+
}
316+
308317
public function testCookies()
309318
{
310319
$test = new Test();

tests/PHPCurlClass/server.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@
7979
header('Content-Type: application/json');
8080
header('ETag: ' . md5('worldpeace'));
8181
exit;
82+
} elseif ($test === 'response_body') {
83+
echo 'OK';
84+
exit;
8285
} elseif ($test === 'json_response') {
8386
$key = $_POST['key'];
8487
$value = $_POST['value'];

0 commit comments

Comments
 (0)