Fix #10: Remove trailing ? from request urls

This commit is contained in:
Zach Borboa
2013-12-13 22:54:09 -08:00
parent 54bb4a943b
commit 684c9d9071
2 changed files with 15 additions and 5 deletions
+8 -4
View File
@@ -36,13 +36,13 @@ class Curl {
}
public function get($url, $data=array()) {
$this->setopt(CURLOPT_URL, $url . '?' . http_build_query($data));
$this->setopt(CURLOPT_URL, $this->_buildURL($url, $data));
$this->setopt(CURLOPT_HTTPGET, TRUE);
return $this->_exec();
}
public function post($url, $data=array()) {
$this->setopt(CURLOPT_URL, $url);
$this->setopt(CURLOPT_URL, $this->_buildURL($url));
$this->setopt(CURLOPT_POST, TRUE);
$this->setopt(CURLOPT_POSTFIELDS, $this->_postfields($data));
return $this->_exec();
@@ -56,14 +56,14 @@ class Curl {
}
public function patch($url, $data=array()) {
$this->setopt(CURLOPT_URL, $url);
$this->setopt(CURLOPT_URL, $this->_buildURL($url));
$this->setopt(CURLOPT_CUSTOMREQUEST, 'PATCH');
$this->setopt(CURLOPT_POSTFIELDS, $data);
return $this->_exec();
}
public function delete($url, $data=array()) {
$this->setopt(CURLOPT_URL, $url . '?' . http_build_query($data));
$this->setopt(CURLOPT_URL, $this->_buildURL($url, $data));
$this->setopt(CURLOPT_CUSTOMREQUEST, 'DELETE');
return $this->_exec();
}
@@ -121,6 +121,10 @@ class Curl {
return implode('&', $query);
}
private function _buildURL($url, $data=array()) {
return $url . (empty($data) ? '' : '?' . http_build_query($data));
}
private function _postfields($data) {
if (is_array($data)) {
if (is_array_multidim($data)) {
+7 -1
View File
@@ -190,9 +190,15 @@ class CurlTest extends PHPUnit_Framework_TestCase {
}
public function testRequestURL() {
$test = new Test();
$this->assertFalse(substr($test->server('request_uri', 'GET'), -1) === '?');
$test = new Test();
$this->assertFalse(substr($test->server('request_uri', 'POST'), -1) === '?');
$test = new Test();
$this->assertFalse(substr($test->server('request_uri', 'GET'), -1) === '?');
$this->assertFalse(substr($test->server('request_uri', 'PUT'), -1) === '?');
$test = new Test();
$this->assertFalse(substr($test->server('request_uri', 'PATCH'), -1) === '?');
$test = new Test();
$this->assertFalse(substr($test->server('request_uri', 'DELETE'), -1) === '?');
}
}