diff --git a/library/Guzzle/Guzzle.php b/library/Guzzle/Guzzle.php index 8ddec715..983be67b 100644 --- a/library/Guzzle/Guzzle.php +++ b/library/Guzzle/Guzzle.php @@ -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; + } } \ No newline at end of file diff --git a/library/Guzzle/Http/Curl/CurlFactory.php b/library/Guzzle/Http/Curl/CurlFactory.php index 96aa93ac..8e18a52f 100644 --- a/library/Guzzle/Http/Curl/CurlFactory.php +++ b/library/Guzzle/Http/Curl/CurlFactory.php @@ -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; } diff --git a/tests/Guzzle/Tests/GuzzleTest.php b/tests/Guzzle/Tests/GuzzleTest.php index aab1554f..e02a2db2 100644 --- a/tests/Guzzle/Tests/GuzzleTest.php +++ b/tests/Guzzle/Tests/GuzzleTest.php @@ -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')); + } + } } \ No newline at end of file