mirror of
https://github.com/guzzle/guzzle.git
synced 2025-02-13 03:45:22 +01:00
[Http] Only checking if CURLOPT_TIMEOUT_MS is set if the version of curl is > 7.16.2. Storing a cached version of curl_version in Guzzle\Guzzle to speed up any checks on curl_version information.
This commit is contained in:
parent
45fd67b4f3
commit
fd0b13140c
@ -23,8 +23,12 @@ class Guzzle
|
||||
protected static $userAgent;
|
||||
|
||||
/**
|
||||
* Get the default User-Agent to add to HTTP headers sent through the
|
||||
* library
|
||||
* @var array cURL version information
|
||||
*/
|
||||
protected static $curl;
|
||||
|
||||
/**
|
||||
* Get the default User-Agent to add to requests sent through the library
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@ -32,13 +36,53 @@ class Guzzle
|
||||
{
|
||||
// @codeCoverageIgnoreStart
|
||||
if (!self::$userAgent) {
|
||||
$version = curl_version();
|
||||
self::$userAgent = sprintf('Guzzle/%s (Language=PHP/%s; curl=%s; Host=%s)', Guzzle::VERSION, \PHP_VERSION, $version['version'], $version['host']);
|
||||
$version = self::getCurlInfo();
|
||||
self::$userAgent = sprintf('Guzzle/%s (Language=PHP/%s; curl=%s; Host=%s)',
|
||||
Guzzle::VERSION,
|
||||
\PHP_VERSION,
|
||||
$version['version'],
|
||||
$version['host']
|
||||
);
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
return self::$userAgent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get curl version information and caches a local copy for fast re-use
|
||||
*
|
||||
* @param $type (optional) Version information to retrieve
|
||||
* version_number - cURL 24 bit version number
|
||||
* version - cURL version number, as a string
|
||||
* ssl_version_number - OpenSSL 24 bit version number
|
||||
* ssl_version - OpenSSL version number, as a string
|
||||
* libz_version - zlib version number, as a string
|
||||
* host - Information about the host where cURL was built
|
||||
* age
|
||||
* features - A bitmask of the CURL_VERSION_XXX constants
|
||||
* protocols - An array of protocols names supported by cURL
|
||||
*
|
||||
* @return array|string|float false Returns an array if no $type is
|
||||
* provided, a string|float if a $type is provided and found, or false
|
||||
* if a $type is provided and not found.
|
||||
*/
|
||||
public static function getCurlInfo($type = null)
|
||||
{
|
||||
// @codeCoverageIgnoreStart
|
||||
if (!self::$curl) {
|
||||
self::$curl = curl_version();
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
if (!$type) {
|
||||
return self::$curl;
|
||||
} else if (isset(self::$curl[$type])) {
|
||||
return self::$curl[$type];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an RFC 1123 HTTP-Date from various date values
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace Guzzle\Http\Curl;
|
||||
|
||||
use Guzzle\Guzzle;
|
||||
use Guzzle\Common\Stream\StreamHelper;
|
||||
use Guzzle\Common\Collection;
|
||||
use Guzzle\Http\Url;
|
||||
@ -39,6 +40,11 @@ class CurlHandle
|
||||
*/
|
||||
protected $stderr;
|
||||
|
||||
/**
|
||||
* @var array Statically cached array of cURL options that pollute handles
|
||||
*/
|
||||
protected static $pollute;
|
||||
|
||||
/**
|
||||
* Construct a new CurlHandle object that wraps a cURL handle
|
||||
*
|
||||
@ -340,18 +346,26 @@ class CurlHandle
|
||||
*/
|
||||
public function hasProblematicOption()
|
||||
{
|
||||
// The following options cannot be unset
|
||||
return 0 != count(array_intersect(array(
|
||||
CURLOPT_RANGE,
|
||||
CURLOPT_COOKIEFILE,
|
||||
CURLOPT_COOKIEJAR,
|
||||
CURLOPT_LOW_SPEED_LIMIT,
|
||||
CURLOPT_LOW_SPEED_TIME,
|
||||
CURLOPT_TIMEOUT,
|
||||
CURLOPT_TIMEOUT_MS,
|
||||
CURLOPT_FORBID_REUSE,
|
||||
CURLOPT_RESUME_FROM,
|
||||
CURLOPT_HTTPAUTH
|
||||
), $this->options->getKeys()));
|
||||
if (!self::$pollute) {
|
||||
self::$pollute = array(
|
||||
CURLOPT_RANGE,
|
||||
CURLOPT_COOKIEFILE,
|
||||
CURLOPT_COOKIEJAR,
|
||||
CURLOPT_LOW_SPEED_LIMIT,
|
||||
CURLOPT_LOW_SPEED_TIME,
|
||||
CURLOPT_TIMEOUT,
|
||||
CURLOPT_TIMEOUT_MS,
|
||||
CURLOPT_FORBID_REUSE,
|
||||
CURLOPT_RESUME_FROM,
|
||||
CURLOPT_HTTPAUTH
|
||||
);
|
||||
|
||||
// CURLOPT_TIMEOUT_MS was added in v7.16.2
|
||||
if (Guzzle::getCurlInfo('version') > '7.16.2') {
|
||||
self::$pollute[] = \CURLOPT_TIMEOUT_MS;
|
||||
}
|
||||
}
|
||||
|
||||
return count(array_intersect(self::$pollute, $this->options->getKeys())) > 0;
|
||||
}
|
||||
}
|
@ -70,4 +70,15 @@ class GuzzleTest extends GuzzleTestCase
|
||||
{
|
||||
$this->assertEquals($output, Guzzle::inject($input, new Collection($config)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Guzzle\Guzzle::getCurlInfo
|
||||
*/
|
||||
public function testCachesCurlInfo()
|
||||
{
|
||||
$c = curl_version();
|
||||
$this->assertInternalType('array', Guzzle::getCurlInfo());
|
||||
$this->assertEquals(false, Guzzle::getCurlInfo('ewfewfewfe'));
|
||||
$this->assertEquals($c['version'], Guzzle::getCurlInfo('version'));
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user