mirror of
https://github.com/php-curl-class/php-curl-class.git
synced 2026-09-07 08:56:55 +00:00
Add setHeaders() method and test
This commit is contained in:
@@ -53,6 +53,11 @@ class Curl {
|
||||
$this->setopt(CURLOPT_USERPWD, $username . ':' . $password);
|
||||
}
|
||||
|
||||
function setHeader($key, $value) {
|
||||
$this->_headers[$key] = $key . ': ' . $value;
|
||||
$this->setopt(CURLOPT_HTTPHEADER, array_values($this->_headers));
|
||||
}
|
||||
|
||||
function setUserAgent($user_agent) {
|
||||
$this->setopt(CURLOPT_USERAGENT, $user_agent);
|
||||
}
|
||||
@@ -97,6 +102,7 @@ class Curl {
|
||||
}
|
||||
|
||||
private $_cookies = array();
|
||||
private $_headers = array();
|
||||
|
||||
public $curl;
|
||||
public $error = NULL;
|
||||
|
||||
@@ -80,4 +80,14 @@ class CurlTest extends PHPUnit_Framework_TestCase {
|
||||
$this->assertTrue($test->curl->error === TRUE);
|
||||
$this->assertTrue($test->curl->error_code === CURLE_OPERATION_TIMEOUTED);
|
||||
}
|
||||
|
||||
public function testHeaders() {
|
||||
$test = new Test();
|
||||
$test->curl->setHeader('Content-Type', 'application/json');
|
||||
$test->curl->setHeader('X-Requested-With', 'XMLHttpRequest');
|
||||
$test->curl->setHeader('Accept', 'application/json');
|
||||
$this->assertTrue($test->server('GET', 'server', 'CONTENT_TYPE') === 'application/json');
|
||||
$this->assertTrue($test->server('GET', 'server', 'HTTP_X_REQUESTED_WITH') === 'XMLHttpRequest');
|
||||
$this->assertTrue($test->server('GET', 'server', 'HTTP_ACCEPT') === 'application/json');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user