Fix #234 Fixed PATCH request method to correctly support sending body data.

This commit is contained in:
Pete Watts
2015-08-20 12:26:22 +01:00
parent a7ed5182da
commit 9d03d46290
3 changed files with 21 additions and 4 deletions
+5 -4
View File
@@ -441,6 +441,11 @@ class Curl
$data = $url;
$url = $this->baseUrl;
}
if (is_array($data) && empty($data)) {
$this->unsetHeader('Content-Length');
}
$this->setURL($url);
$this->setOpt(CURLOPT_CUSTOMREQUEST, 'PATCH');
$this->setOpt(CURLOPT_POSTFIELDS, $this->buildPostData($data));
@@ -463,10 +468,6 @@ class Curl
$url = $this->baseUrl;
}
if (is_array($data) && empty($data)) {
$this->unsetHeader('Content-Length');
}
$this->setURL($url);
$this->setOpt(CURLOPT_CUSTOMREQUEST, 'POST');
$this->setOpt(CURLOPT_POST, true);
+13
View File
@@ -409,6 +409,19 @@ class CurlTest extends PHPUnit_Framework_TestCase
$this->assertEquals('PATCH', $test->server('request_method', 'PATCH'));
}
public function testPatchData()
{
$test = new Test();
$this->assertEquals('key=value', $test->server('patch', 'PATCH', array(
'key' => 'value',
)));
$test = new Test();
$this->assertEquals('{"key":"value"}', $test->server('patch', 'PATCH', json_encode(array(
'key' => 'value',
))));
}
public function testPatchRequestMethodWithMultidimArray()
{
$data = array(
+3
View File
@@ -107,6 +107,9 @@ if ($test == 'http_basic_auth') {
} elseif ($test === 'put') {
echo $http_raw_post_data;
exit;
} elseif ($test === 'patch') {
echo $http_raw_post_data;
exit;
} elseif ($test === 'post_multidimensional') {
echo $http_raw_post_data;
exit;