Skip to content
This repository was archived by the owner on Jan 30, 2020. It is now read-only.

Commit 95f0910

Browse files
committed
Merge branch 'hotfix/zendframework/zendframework#6492-support-delete-post-request-body'
Close zendframework/zendframework#6492
5 parents 651043c + 94deaef + ffd4e9b + 2aef442 + 281d6f9 commit 95f0910

File tree

6 files changed

+75
-18
lines changed

6 files changed

+75
-18
lines changed

Diff for: src/Client.php

+13-3
Original file line numberDiff line numberDiff line change
@@ -347,9 +347,19 @@ public function setMethod($method)
347347
{
348348
$method = $this->getRequest()->setMethod($method)->getMethod();
349349

350-
if (($method == Request::METHOD_POST || $method == Request::METHOD_PUT ||
351-
$method == Request::METHOD_DELETE || $method == Request::METHOD_PATCH)
352-
&& empty($this->encType)) {
350+
if (empty($this->encType)
351+
&& in_array(
352+
$method,
353+
array(
354+
Request::METHOD_POST,
355+
Request::METHOD_PUT,
356+
Request::METHOD_DELETE,
357+
Request::METHOD_PATCH,
358+
Request::METHOD_OPTIONS,
359+
),
360+
true
361+
)
362+
) {
353363
$this->setEncType(self::ENC_URLENCODED);
354364
}
355365

Diff for: src/Client/Adapter/Curl.php

+1-9
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ public function write($method, $uri, $httpVersion = 1.1, $headers = array(), $bo
375375
* Make sure POSTFIELDS is set after $curlMethod is set:
376376
* @link http://de2.php.net/manual/en/function.curl-setopt.php#81161
377377
*/
378-
if ($method == 'POST') {
378+
if (in_array($method, array('POST', 'PATCH', 'DELETE', 'OPTIONS'), true)) {
379379
curl_setopt($this->curl, CURLOPT_POSTFIELDS, $body);
380380
} elseif ($curlMethod == CURLOPT_UPLOAD) {
381381
// this covers a PUT by file-handle:
@@ -385,14 +385,6 @@ public function write($method, $uri, $httpVersion = 1.1, $headers = array(), $bo
385385
curl_setopt($this->curl, CURLOPT_INFILESIZE, $this->config['curloptions'][CURLOPT_INFILESIZE]);
386386
unset($this->config['curloptions'][CURLOPT_INFILE]);
387387
unset($this->config['curloptions'][CURLOPT_INFILESIZE]);
388-
} elseif ($method == 'PUT') {
389-
// This is a PUT by a setRawData string, not by file-handle
390-
curl_setopt($this->curl, CURLOPT_POSTFIELDS, $body);
391-
} elseif ($method == 'PATCH') {
392-
curl_setopt($this->curl, CURLOPT_POSTFIELDS, $body);
393-
} elseif ($method == 'DELETE' && $body) {
394-
// DELETE requests can also have a body
395-
curl_setopt($this->curl, CURLOPT_POSTFIELDS, $body);
396388
}
397389

398390
// set additional curl options

Diff for: test/Client/CommonHttpTests.php

+40
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,46 @@ public function testPatchData($params)
211211
$this->assertEquals(serialize($params), $res->getBody(), "PATCH data integrity test failed");
212212
}
213213

214+
/**
215+
* Test we can properly send DELETE parameters with
216+
* application/x-www-form-urlencoded content type
217+
*
218+
* @dataProvider parameterArrayProvider
219+
*/
220+
public function testDeleteData($params)
221+
{
222+
$client = $this->client;
223+
$client->setUri($this->baseuri . 'testDeleteData.php');
224+
225+
$client->setRawBody(serialize($params));
226+
227+
$client->setMethod('DELETE');
228+
$this->assertEquals($client::ENC_URLENCODED, $this->client->getEncType());
229+
$this->assertTrue($client->getRequest()->isDelete());
230+
$res = $this->client->send();
231+
$this->assertEquals(serialize($params), $res->getBody(), "DELETE data integrity test failed");
232+
}
233+
234+
/**
235+
* Test we can properly send OPTIONS parameters with
236+
* application/x-www-form-urlencoded content type
237+
*
238+
* @dataProvider parameterArrayProvider
239+
*/
240+
public function testOptionsData($params)
241+
{
242+
$client = $this->client;
243+
$client->setUri($this->baseuri . 'testOptionsData.php');
244+
245+
$client->setRawBody(serialize($params));
246+
247+
$client->setMethod('OPTIONS');
248+
$this->assertEquals($client::ENC_URLENCODED, $this->client->getEncType());
249+
$this->assertTrue($client->getRequest()->isOptions());
250+
$res = $this->client->send();
251+
$this->assertEquals(serialize($params), $res->getBody(), "OPTIONS data integrity test failed");
252+
}
253+
214254
/**
215255
* Test we can properly send POST parameters with
216256
* multipart/form-data content type

Diff for: test/Client/_files/testDeleteData.php

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
/**
3+
* Zend Framework (http://framework.zend.com/)
4+
*
5+
* @link http://github.com/zendframework/zf2 for the canonical source repository
6+
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
7+
* @license http://framework.zend.com/license/new-bsd New BSD License
8+
*/
9+
10+
readfile("php://input");

Diff for: test/Client/_files/testOptionsData.php

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
/**
3+
* Zend Framework (http://framework.zend.com/)
4+
*
5+
* @link http://github.com/zendframework/zf2 for the canonical source repository
6+
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
7+
* @license http://framework.zend.com/license/new-bsd New BSD License
8+
*/
9+
10+
readfile("php://input");

Diff for: test/Client/_files/testPatchData.php

+1-6
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,4 @@
77
* @license http://framework.zend.com/license/new-bsd New BSD License
88
*/
99

10-
$putdata = fopen("php://input", "r");
11-
while ($data = fread($putdata, 1024)) {
12-
echo $data;
13-
}
14-
15-
fclose($putdata);
10+
readfile("php://input");

0 commit comments

Comments
 (0)