mirror of
https://github.com/guzzle/guzzle.git
synced 2025-02-24 18:13:00 +01:00
[Http] Correcting the version reported in the User-Agent header. Shortening the User-Agent header.
Adding a way to black list cURL options and cURL specific headers from being set or sent over the wire.
This commit is contained in:
parent
2be94b1981
commit
503df1835f
@ -9,7 +9,7 @@ use Guzzle\Common\Collection;
|
||||
*/
|
||||
class Guzzle
|
||||
{
|
||||
const VERSION = '2.0';
|
||||
const VERSION = '2.3.2';
|
||||
|
||||
/**
|
||||
* @var array Guzzle cache
|
||||
@ -24,11 +24,11 @@ class Guzzle
|
||||
public static function getDefaultUserAgent()
|
||||
{
|
||||
if (!isset(self::$cache['user_agent'])) {
|
||||
self::$cache['user_agent'] = sprintf('Guzzle/%s (Language=PHP/%s; curl=%s; Host=%s)',
|
||||
self::$cache['user_agent'] = sprintf('Guzzle/%s (PHP=%s; curl=%s; openssl=%s)',
|
||||
self::VERSION,
|
||||
\PHP_VERSION,
|
||||
self::getCurlInfo('version'),
|
||||
self::getCurlInfo('host')
|
||||
self::getCurlInfo('ssl_version')
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -269,7 +269,7 @@ class Client extends AbstractHasDispatcher implements ClientInterface
|
||||
|
||||
foreach ($this->getConfig()->getAll() as $key => $value) {
|
||||
// Add any curl options that might in the config to the request
|
||||
if (strpos($key, 'curl.') === 0) {
|
||||
if (strpos($key, 'curl.') === 0 && $key != 'curl.black_list') {
|
||||
$curlOption = str_replace('curl.', '', $key);
|
||||
if (defined($curlOption)) {
|
||||
$curlValue = is_string($value) && defined($value) ? constant($value) : $value;
|
||||
|
@ -161,6 +161,18 @@ class CurlHandle
|
||||
}
|
||||
}
|
||||
|
||||
// Check if any headers or cURL options are blacklisted
|
||||
$client = $request->getClient();
|
||||
if ($client && $client->getConfig('curl.black_list')) {
|
||||
foreach ($client->getConfig('curl.black_list') as $value) {
|
||||
if (strpos($value, 'header.') === 0) {
|
||||
$curlOptions[CURLOPT_HTTPHEADER][] = substr($value, 7) . ':';
|
||||
} else {
|
||||
unset($curlOptions[$value]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Apply the options to the cURL handle.
|
||||
curl_setopt_array($handle, $curlOptions);
|
||||
$request->getParams()->set('curl.last_options', $curlOptions);
|
||||
|
@ -14,7 +14,7 @@ class GuzzleTest extends GuzzleTestCase
|
||||
{
|
||||
Guzzle::reset();
|
||||
$version = curl_version();
|
||||
$agent = sprintf('Guzzle/%s (Language=PHP/%s; curl=%s; Host=%s)', Guzzle::VERSION, \PHP_VERSION, $version['version'], $version['host']);
|
||||
$agent = sprintf('Guzzle/%s (PHP=%s; curl=%s; openssl=%s)', Guzzle::VERSION, \PHP_VERSION, $version['version'], $version['ssl_version']);
|
||||
$this->assertEquals($agent, Guzzle::getDefaultUserAgent());
|
||||
// Get it from cache this time
|
||||
$this->assertEquals($agent, Guzzle::getDefaultUserAgent());
|
||||
|
@ -134,7 +134,7 @@ class CurlHandleTest extends \Guzzle\Tests\GuzzleTestCase
|
||||
if (!defined('CURLOPT_TIMEOUT_MS')) {
|
||||
$this->markTestSkipped('Update curl');
|
||||
}
|
||||
|
||||
|
||||
$settings = array(
|
||||
CURLOPT_PORT => 123,
|
||||
CURLOPT_CONNECTTIMEOUT_MS => 1
|
||||
@ -700,4 +700,20 @@ class CurlHandleTest extends \Guzzle\Tests\GuzzleTestCase
|
||||
$this->assertTrue(in_array('Expect:', $headers));
|
||||
$this->assertTrue(in_array('Accept:', $headers));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Guzzle\Http\Curl\CurlHandle::factory
|
||||
*/
|
||||
public function testHeadersCanBeBlacklisted()
|
||||
{
|
||||
$request = RequestFactory::getInstance()->create('PUT', $this->getServer()->getUrl());
|
||||
$request->setClient(new Client('http://www.example.com', array(
|
||||
'curl.black_list' => array('header.Accept', 'header.Foo', CURLOPT_ENCODING)
|
||||
)));
|
||||
$handle = CurlHandle::factory($request);
|
||||
$headers = $handle->getOptions()->get(CURLOPT_HTTPHEADER);
|
||||
$this->assertTrue(in_array('Accept:', $headers));
|
||||
$this->assertTrue(in_array('Foo:', $headers));
|
||||
$this->assertFalse($handle->getOptions()->hasKey(CURLOPT_ENCODING));
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user