mirror of
https://github.com/guzzle/guzzle.git
synced 2025-02-13 03:45:22 +01:00
[Http] Only adding CURLOPT_FOLLOWLOCATION to cURL handles if open_basedir is not set
This commit is contained in:
parent
fd0b13140c
commit
cf58b2c82e
@ -72,6 +72,8 @@ class Guzzle
|
||||
// @codeCoverageIgnoreStart
|
||||
if (!self::$curl) {
|
||||
self::$curl = curl_version();
|
||||
// Check if CURLOPT_FOLLOWLOCATION is available
|
||||
self::$curl['follow_location'] = !ini_get('open_basedir');
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
@ -93,7 +95,11 @@ class Guzzle
|
||||
*/
|
||||
public static function getHttpDate($date)
|
||||
{
|
||||
return gmdate('D, d M Y H:i:s', (!is_numeric($date)) ? strtotime($date) : $date) . ' GMT';
|
||||
if (!is_numeric($date)) {
|
||||
$date = strtotime($date);
|
||||
}
|
||||
|
||||
return gmdate('D, d M Y H:i:s', $date) . ' GMT';
|
||||
}
|
||||
|
||||
/**
|
||||
@ -117,4 +123,13 @@ class Guzzle
|
||||
}, $input
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the cached internal state
|
||||
*/
|
||||
public static function reset()
|
||||
{
|
||||
self::$userAgent = null;
|
||||
self::$curl = null;
|
||||
}
|
||||
}
|
@ -326,8 +326,6 @@ class CurlFactory implements CurlFactoryInterface
|
||||
CURLOPT_CONNECTTIMEOUT => 120, // Connect timeout in seconds
|
||||
CURLOPT_RETURNTRANSFER => false, // Streaming the return, so no need
|
||||
CURLOPT_HEADER => false, // Retrieve the received headers
|
||||
CURLOPT_FOLLOWLOCATION => true, // Follow redirects
|
||||
CURLOPT_MAXREDIRS => 5,
|
||||
CURLOPT_USERAGENT => $request->getHeader('User-Agent', Guzzle::getDefaultUserAgent()),
|
||||
CURLOPT_ENCODING => '', // Supports all encodings
|
||||
CURLOPT_PORT => $request->getPort(),
|
||||
@ -366,6 +364,13 @@ class CurlFactory implements CurlFactoryInterface
|
||||
$curlOptions[CURLOPT_SSL_VERIFYHOST] = false;
|
||||
}
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
if (Guzzle::getCurlInfo('follow_location')) {
|
||||
$curlOptions[CURLOPT_FOLLOWLOCATION] = true;
|
||||
$curlOptions[CURLOPT_MAXREDIRS] = 5;
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
return $curlOptions;
|
||||
}
|
||||
|
||||
|
@ -81,4 +81,18 @@ class GuzzleTest extends GuzzleTestCase
|
||||
$this->assertEquals(false, Guzzle::getCurlInfo('ewfewfewfe'));
|
||||
$this->assertEquals($c['version'], Guzzle::getCurlInfo('version'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Guzzle\Guzzle::getCurlInfo
|
||||
* @covers Guzzle\Guzzle::reset
|
||||
*/
|
||||
public function testDeterminesIfCurlCanFollowLocation()
|
||||
{
|
||||
Guzzle::reset();
|
||||
if (!ini_get('open_basedir')) {
|
||||
$this->assertTrue(Guzzle::getCurlInfo('follow_location'));
|
||||
} else {
|
||||
$this->assertFalse(Guzzle::getCurlInfo('follow_location'));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user