diff --git a/src/Curl/Curl.php b/src/Curl/Curl.php index 6986f29..38a2162 100644 --- a/src/Curl/Curl.php +++ b/src/Curl/Curl.php @@ -265,7 +265,9 @@ class Curl $this->setUrl($url, $query_parameters); $this->setOpt(CURLOPT_CUSTOMREQUEST, 'DELETE'); - $this->setOpt(CURLOPT_POSTFIELDS, $this->buildPostData($data)); + if (!empty($data)) { + $this->setOpt(CURLOPT_POSTFIELDS, $this->buildPostData($data)); + } return $this->exec(); } diff --git a/tests/PHPCurlClass/PHPCurlClassTest.php b/tests/PHPCurlClass/PHPCurlClassTest.php index b823d95..3fdcf15 100644 --- a/tests/PHPCurlClass/PHPCurlClassTest.php +++ b/tests/PHPCurlClass/PHPCurlClassTest.php @@ -622,6 +622,22 @@ class CurlTest extends \PHPUnit\Framework\TestCase $this->assertEquals('{"get":{"foo":"bar"},"delete":{"wibble":"wubble"}}', $test->curl->rawResponse); } + public function testDeleteContentLengthSetWithBody() + { + $request_body = 'a=1&b=2&c=3'; + $test = new Test(); + $test->server('request_method', 'DELETE', array(), $request_body); + $this->assertEquals(strlen($request_body), $test->curl->requestHeaders['content-length']); + } + + public function testDeleteContentLengthUnsetWithoutBody() + { + $request_body = array(); + $test = new Test(); + $test->server('request_method', 'DELETE', array(), $request_body); + $this->assertFalse(isset($test->curl->requestHeaders['content-length'])); + } + public function testHeadRequestMethod() { $test = new Test();