Fix #22: Include CURLOPT_CUSTOMREQUEST to override any existing request method

This commit is contained in:
Zach Borboa
2014-03-01 02:31:23 -08:00
parent 52957b5ce2
commit a7590c8660
2 changed files with 29 additions and 1 deletions
+2 -1
View File
@@ -46,7 +46,6 @@ class Curl {
}
public function get($url_mixed, $data=array()) {
$this->setOpt(CURLOPT_CUSTOMREQUEST, 'GET');
if (is_array($url_mixed)) {
$curl_multi = curl_multi_init();
$this->_multi_parent = true;
@@ -57,6 +56,7 @@ class Curl {
$curl = new Curl();
$curl->_multi_child = true;
$curl->setOpt(CURLOPT_URL, $this->_buildURL($url, $data), $curl->curl);
$curl->setOpt(CURLOPT_CUSTOMREQUEST, 'GET');
$curl->setOpt(CURLOPT_HTTPGET, true);
$this->_call($this->_before_send, $curl);
$this->curls[] = $curl;
@@ -84,6 +84,7 @@ class Curl {
}
else {
$this->setopt(CURLOPT_URL, $this->_buildURL($url_mixed, $data));
$this->setOpt(CURLOPT_CUSTOMREQUEST, 'GET');
$this->setopt(CURLOPT_HTTPGET, true);
return $this->exec();
}
+27
View File
@@ -527,4 +527,31 @@ class CurlTest extends PHPUnit_Framework_TestCase {
$curl = new Curl();
$curl->setOpt(CURLOPT_RETURNTRANSFER, false);
}
public function testRequestMethodSuccessiveRequests() {
$test = new Test();
function test($instance, $before, $after) {
$instance->server('server', $before, array('key' => 'REQUEST_METHOD'));
PHPUnit_Framework_Assert::assertTrue($instance->curl->response === $before);
$instance->server('server', $after, array('key' => 'REQUEST_METHOD'));
PHPUnit_Framework_Assert::assertTrue($instance->curl->response === $after);
}
test($test, 'GET', 'POST');
test($test, 'GET', 'PUT');
test($test, 'GET', 'DELETE');
test($test, 'POST', 'GET');
test($test, 'POST', 'PUT');
test($test, 'POST', 'DELETE');
test($test, 'PUT', 'GET');
test($test, 'PUT', 'POST');
test($test, 'PUT', 'DELETE');
test($test, 'DELETE', 'GET');
test($test, 'DELETE', 'POST');
test($test, 'DELETE', 'PUT');
}
}