Skip to content

Commit 9edf511

Browse files
authored
Merge pull request php-curl-class#558 from zachborboa/master
Add tests for content-length with DELETE requests
2 parents 1e70527 + bf68fc3 commit 9edf511

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/Curl/Curl.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,9 @@ public function delete($url, $query_parameters = array(), $data = array())
265265

266266
$this->setUrl($url, $query_parameters);
267267
$this->setOpt(CURLOPT_CUSTOMREQUEST, 'DELETE');
268-
$this->setOpt(CURLOPT_POSTFIELDS, $this->buildPostData($data));
268+
if (!empty($data)) {
269+
$this->setOpt(CURLOPT_POSTFIELDS, $this->buildPostData($data));
270+
}
269271
return $this->exec();
270272
}
271273

tests/PHPCurlClass/PHPCurlClassTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,22 @@ public function testDeleteRequestBody()
622622
$this->assertEquals('{"get":{"foo":"bar"},"delete":{"wibble":"wubble"}}', $test->curl->rawResponse);
623623
}
624624

625+
public function testDeleteContentLengthSetWithBody()
626+
{
627+
$request_body = 'a=1&b=2&c=3';
628+
$test = new Test();
629+
$test->server('request_method', 'DELETE', array(), $request_body);
630+
$this->assertEquals(strlen($request_body), $test->curl->requestHeaders['content-length']);
631+
}
632+
633+
public function testDeleteContentLengthUnsetWithoutBody()
634+
{
635+
$request_body = array();
636+
$test = new Test();
637+
$test->server('request_method', 'DELETE', array(), $request_body);
638+
$this->assertFalse(isset($test->curl->requestHeaders['content-length']));
639+
}
640+
625641
public function testHeadRequestMethod()
626642
{
627643
$test = new Test();

0 commit comments

Comments
 (0)