mirror of
https://github.com/php-curl-class/php-curl-class.git
synced 2026-09-19 06:46:45 +00:00
Add preliminary support for HHVM
This commit is contained in:
+13
-2
@@ -93,6 +93,10 @@ class Curl
|
||||
|
||||
public function post($url, $data = array())
|
||||
{
|
||||
if (is_array($data) && empty($data)) {
|
||||
$this->setHeader('Content-Length');
|
||||
}
|
||||
|
||||
$this->setOpt(CURLOPT_URL, $this->buildURL($url));
|
||||
$this->setOpt(CURLOPT_CUSTOMREQUEST, 'POST');
|
||||
$this->setOpt(CURLOPT_POST, true);
|
||||
@@ -104,12 +108,17 @@ class Curl
|
||||
{
|
||||
$this->setOpt(CURLOPT_URL, $url);
|
||||
$this->setOpt(CURLOPT_CUSTOMREQUEST, 'PUT');
|
||||
$this->setOpt(CURLOPT_POSTFIELDS, http_build_query($data));
|
||||
$put_data = http_build_query($data);
|
||||
if (empty($this->options[CURLOPT_INFILE]) && empty($this->options[CURLOPT_INFILESIZE])) {
|
||||
$this->setHeader('Content-Length', strlen($put_data));
|
||||
}
|
||||
$this->setOpt(CURLOPT_POSTFIELDS, $put_data);
|
||||
return $this->exec();
|
||||
}
|
||||
|
||||
public function patch($url, $data = array())
|
||||
{
|
||||
$this->setHeader('Content-Length');
|
||||
$this->setOpt(CURLOPT_URL, $this->buildURL($url));
|
||||
$this->setOpt(CURLOPT_CUSTOMREQUEST, 'PATCH');
|
||||
$this->setOpt(CURLOPT_POSTFIELDS, $data);
|
||||
@@ -118,6 +127,7 @@ class Curl
|
||||
|
||||
public function delete($url, $data = array())
|
||||
{
|
||||
$this->setHeader('Content-Length');
|
||||
$this->setOpt(CURLOPT_URL, $this->buildURL($url, $data));
|
||||
$this->setOpt(CURLOPT_CUSTOMREQUEST, 'DELETE');
|
||||
return $this->exec();
|
||||
@@ -133,6 +143,7 @@ class Curl
|
||||
|
||||
public function options($url, $data = array())
|
||||
{
|
||||
$this->setHeader('Content-Length');
|
||||
$this->setOpt(CURLOPT_URL, $this->buildURL($url, $data));
|
||||
$this->setOpt(CURLOPT_CUSTOMREQUEST, 'OPTIONS');
|
||||
return $this->exec();
|
||||
@@ -144,7 +155,7 @@ class Curl
|
||||
$this->setOpt(CURLOPT_USERPWD, $username . ':' . $password);
|
||||
}
|
||||
|
||||
public function setHeader($key, $value)
|
||||
public function setHeader($key, $value = '')
|
||||
{
|
||||
$this->headers[$key] = $key . ': ' . $value;
|
||||
$this->setOpt(CURLOPT_HTTPHEADER, array_values($this->headers));
|
||||
|
||||
@@ -278,9 +278,16 @@ class CurlTest extends PHPUnit_Framework_TestCase {
|
||||
}
|
||||
|
||||
public function testMultipleCookieResponse() {
|
||||
$expected_response = 'cookie1=scrumptious,cookie2=mouthwatering';
|
||||
|
||||
// github.com/facebook/hhvm/issues/2345
|
||||
if (defined('HHVM_VERSION')) {
|
||||
$expected_response = 'cookie2=mouthwatering,cookie1=scrumptious';
|
||||
}
|
||||
|
||||
$test = new Test();
|
||||
$test->server('multiple_cookie', 'GET');
|
||||
$this->assertEquals($test->curl->response_headers['Set-Cookie'], 'cookie1=scrumptious,cookie2=mouthwatering');
|
||||
$this->assertEquals($test->curl->response_headers['Set-Cookie'], $expected_response);
|
||||
}
|
||||
|
||||
public function testError() {
|
||||
@@ -295,7 +302,13 @@ class CurlTest extends PHPUnit_Framework_TestCase {
|
||||
public function testErrorMessage() {
|
||||
$test = new Test();
|
||||
$test->server('error_message', 'GET');
|
||||
$this->assertTrue($test->curl->error_message === 'HTTP/1.1 401 Unauthorized');
|
||||
|
||||
$expected_response = 'HTTP/1.1 401 Unauthorized';
|
||||
if (defined('HHVM_VERSION')) {
|
||||
$expected_response = 'HTTP/1.1 401';
|
||||
}
|
||||
|
||||
$this->assertEquals($test->curl->error_message, $expected_response);
|
||||
}
|
||||
|
||||
public function testHeaders() {
|
||||
|
||||
Reference in New Issue
Block a user