mirror of
https://github.com/php-curl-class/php-curl-class.git
synced 2026-09-03 06:07:05 +00:00
Include querystring data in the url for the appropriate HTTP request methods
This commit is contained in:
+11
-7
@@ -62,8 +62,10 @@ class Curl
|
||||
foreach ($url_mixed as $url) {
|
||||
$curl = new Curl();
|
||||
$curl->multi_child = true;
|
||||
|
||||
$url = $this->buildURL($url, $data);
|
||||
$curl->setUrl($url);
|
||||
$curl->setOpt(CURLOPT_URL, $this->buildURL($url, $data), $curl->curl);
|
||||
$curl->setOpt(CURLOPT_URL, $url, $curl->curl);
|
||||
$curl->setOpt(CURLOPT_CUSTOMREQUEST, 'GET');
|
||||
$curl->setOpt(CURLOPT_HTTPGET, true);
|
||||
$this->call($this->before_send_function, $curl);
|
||||
@@ -101,8 +103,9 @@ class Curl
|
||||
$this->exec($ch);
|
||||
}
|
||||
} else {
|
||||
$this->setUrl($url_mixed);
|
||||
$this->setopt(CURLOPT_URL, $this->buildURL($url_mixed, $data));
|
||||
$url = $this->buildURL($url_mixed, $data);
|
||||
$this->setUrl($url);
|
||||
$this->setopt(CURLOPT_URL, $url);
|
||||
$this->setOpt(CURLOPT_CUSTOMREQUEST, 'GET');
|
||||
$this->setopt(CURLOPT_HTTPGET, true);
|
||||
return $this->exec();
|
||||
@@ -157,8 +160,9 @@ class Curl
|
||||
|
||||
public function head($url, $data = array())
|
||||
{
|
||||
$url = $this->buildURL($url, $data);
|
||||
$this->setUrl($url);
|
||||
$this->setOpt(CURLOPT_URL, $this->buildURL($url, $data));
|
||||
$this->setOpt(CURLOPT_URL, $url);
|
||||
$this->setOpt(CURLOPT_CUSTOMREQUEST, 'HEAD');
|
||||
$this->setOpt(CURLOPT_NOBODY, true);
|
||||
return $this->exec();
|
||||
@@ -243,17 +247,17 @@ class Curl
|
||||
$this->options[$option] = $value;
|
||||
return curl_setopt($ch, $option, $value);
|
||||
}
|
||||
|
||||
|
||||
public function getOpt($option)
|
||||
{
|
||||
return $this->options[$option];
|
||||
}
|
||||
|
||||
|
||||
public function setUrl($url)
|
||||
{
|
||||
$this->url = $url;
|
||||
}
|
||||
|
||||
|
||||
public function getUrl()
|
||||
{
|
||||
return $this->url;
|
||||
|
||||
@@ -91,17 +91,45 @@ class CurlTest extends PHPUnit_Framework_TestCase
|
||||
'key' => 'REQUEST_METHOD',
|
||||
)));
|
||||
}
|
||||
|
||||
|
||||
public function testGetUrl()
|
||||
{
|
||||
$data = array('foo' => 'bar');
|
||||
|
||||
// curl -v --get "http://127.0.0.1:8000/" -d "foo=bar"
|
||||
$test = new Test();
|
||||
$verbs = array('GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS');
|
||||
|
||||
foreach ($verbs as $verb) {
|
||||
$test->server('server', $verb);
|
||||
$this->assertEquals(Test::TEST_URL, $test->curl->getUrl());
|
||||
$test->curl->setUrl(''); // reset url in case of the verb method doesn't set url
|
||||
}
|
||||
$test->server('server', 'GET', $data);
|
||||
$this->assertEquals(Test::TEST_URL . '?' . http_build_query($data), $test->curl->getUrl());
|
||||
|
||||
// curl -v --request POST "http://127.0.0.1:8000/" -d "foo=bar"
|
||||
$test = new Test();
|
||||
$test->server('server', 'POST', $data);
|
||||
$this->assertEquals(Test::TEST_URL, $test->curl->getUrl());
|
||||
|
||||
// curl -v --request PUT "http://127.0.0.1:8000/" -d "foo=bar"
|
||||
$test = new Test();
|
||||
$test->server('server', 'PUT', $data);
|
||||
$this->assertEquals(Test::TEST_URL, $test->curl->getUrl());
|
||||
|
||||
// curl -v --request PATCH "http://127.0.0.1:8000/" -d "foo=bar"
|
||||
$test = new Test();
|
||||
$test->server('server', 'PATCH', $data);
|
||||
$this->assertEquals(Test::TEST_URL, $test->curl->getUrl());
|
||||
|
||||
// curl -v --request DELETE "http://127.0.0.1:8000/" -d "foo=bar"
|
||||
$test = new Test();
|
||||
$test->server('server', 'DELETE', $data);
|
||||
$this->assertEquals(Test::TEST_URL, $test->curl->getUrl());
|
||||
|
||||
// curl -v --head --get "http://127.0.0.1:8000/" -d "foo=bar"
|
||||
$test = new Test();
|
||||
$test->server('server', 'HEAD', $data);
|
||||
$this->assertEquals(Test::TEST_URL . '?' . http_build_query($data), $test->curl->getUrl());
|
||||
|
||||
// curl -v --request OPTIONS "http://127.0.0.1:8000/" -d "foo=bar"
|
||||
$test = new Test();
|
||||
$test->server('server', 'OPTIONS', $data);
|
||||
$this->assertEquals(Test::TEST_URL, $test->curl->getUrl());
|
||||
}
|
||||
|
||||
public function testPostRequestMethod()
|
||||
@@ -755,20 +783,20 @@ class CurlTest extends PHPUnit_Framework_TestCase
|
||||
'key' => 'HTTP_USER_AGENT',
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
public function testParallelGetUrl()
|
||||
{
|
||||
$data = array('foo' => 'bar');
|
||||
|
||||
$test = new Test();
|
||||
$curl = $test->curl;
|
||||
$curl->setHeader('X-DEBUG-TEST', 'server');
|
||||
$curl->complete(function ($instance) {
|
||||
PHPUnit_Framework_Assert::assertEquals(Test::TEST_URL, $instance->getUrl());
|
||||
$curl->complete(function ($instance) use ($data) {
|
||||
PHPUnit_Framework_Assert::assertEquals(Test::TEST_URL . '?' . http_build_query($data), $instance->getUrl());
|
||||
});
|
||||
$curl->get(array(
|
||||
Test::TEST_URL,
|
||||
), array(
|
||||
'somedata' => 'thatchangesquerystringbutnotoriginaltesturl'
|
||||
));
|
||||
), $data);
|
||||
}
|
||||
|
||||
public function testParallelGetOptions()
|
||||
@@ -784,7 +812,7 @@ class CurlTest extends PHPUnit_Framework_TestCase
|
||||
Test::TEST_URL,
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
public function testSuccessCallback()
|
||||
{
|
||||
$success_called = false;
|
||||
|
||||
Reference in New Issue
Block a user