From 067d73e6cc19b2d22db0cff025dad5c8b524b85a Mon Sep 17 00:00:00 2001 From: Tam Nguyen Date: Thu, 29 Nov 2018 15:23:24 +0700 Subject: [PATCH 1/2] Only set CURLOPT_POSTFIELDS options if post data is not empty for DELETE method --- src/Curl/Curl.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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(); } From bf68fc30bd2de4bdad00a0d1682934322b82e94a Mon Sep 17 00:00:00 2001 From: Zach Borboa Date: Thu, 29 Nov 2018 23:01:26 -0800 Subject: [PATCH 2/2] Add tests for content-length with DELETE requests (#557) --- tests/PHPCurlClass/PHPCurlClassTest.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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();