mirror of
https://github.com/php-curl-class/php-curl-class.git
synced 2026-08-30 04:01:47 +00:00
Fix #22: Include CURLOPT_CUSTOMREQUEST to override any existing request method
This commit is contained in:
+2
-1
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user