diff --git a/src/Curl/Curl.php b/src/Curl/Curl.php index 038a94a..8a37d1b 100644 --- a/src/Curl/Curl.php +++ b/src/Curl/Curl.php @@ -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); diff --git a/tests/PHPCurlClass/PHPCurlClassTest.php b/tests/PHPCurlClass/PHPCurlClassTest.php index 985657d..367b9d1 100644 --- a/tests/PHPCurlClass/PHPCurlClassTest.php +++ b/tests/PHPCurlClass/PHPCurlClassTest.php @@ -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( diff --git a/tests/PHPCurlClass/server.php b/tests/PHPCurlClass/server.php index eb569bb..c0c20fe 100644 --- a/tests/PHPCurlClass/server.php +++ b/tests/PHPCurlClass/server.php @@ -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;