Fix #58: Include PHP_VERSION and curl version in user-agent

This commit is contained in:
Zach Borboa
2014-05-22 22:28:01 -07:00
parent 0fdbff4b8f
commit 0481920ed3
2 changed files with 18 additions and 6 deletions
+11 -2
View File
@@ -4,7 +4,7 @@ namespace Curl;
class Curl
{
const USER_AGENT = 'PHP-Curl-Class/2.1.0 (+https://github.com/php-curl-class/php-curl-class)';
const VERSION = '2.1.0';
private $cookies = array();
private $headers = array();
@@ -43,7 +43,7 @@ class Curl
}
$this->curl = curl_init();
$this->setUserAgent(self::USER_AGENT);
$this->setDefaultUserAgent();
$this->setOpt(CURLINFO_HEADER_OUT, true);
$this->setOpt(CURLOPT_HEADER, true);
$this->setOpt(CURLOPT_RETURNTRANSFER, true);
@@ -169,6 +169,15 @@ class Curl
unset($this->headers[$key]);
}
public function setDefaultUserAgent()
{
$user_agent = 'PHP-Curl-Class/' . self::VERSION . ' (+https://github.com/php-curl-class/php-curl-class)';
$user_agent .= ' PHP/' . PHP_VERSION;
$curl_version = curl_version();
$user_agent .= ' curl/' . $curl_version['version'];
$this->setUserAgent($user_agent);
}
public function setUserAgent($user_agent)
{
$this->setOpt(CURLOPT_USERAGENT, $user_agent);
+7 -4
View File
@@ -73,11 +73,14 @@ class CurlTest extends PHPUnit_Framework_TestCase
public function testUserAgent()
{
$php_version = 'PHP\/' . PHP_VERSION;
$curl_version = curl_version();
$curl_version = 'curl\/' . $curl_version['version'];
$test = new Test();
$test->curl->setUserAgent(Curl::USER_AGENT);
$this->assertTrue($test->server('server', 'GET', array(
'key' => 'HTTP_USER_AGENT',
)) === Curl::USER_AGENT);
$user_agent = $test->server('server', 'GET', array('key' => 'HTTP_USER_AGENT'));
$this->assertRegExp('/' . $php_version . '/', $user_agent);
$this->assertRegExp('/' . $curl_version . '/', $user_agent);
}
public function testGet()