* @ingroup HTTP
*/
class Http {
+ static $httpEngine = false;
+
/**
* Perform an HTTP request
* @param $method string HTTP method. Usually GET/POST
* @see HttpRequest::__construct
*/
public static function factory( $url, $options ) {
- global $wgHTTPEngine;
- $engine = $wgHTTPEngine;
-
- if ( !$wgHTTPEngine ) {
- $wgHTTPEngine = function_exists( 'curl_init' ) ? 'curl' : 'php';
- } elseif ( $wgHTTPEngine == 'curl' && !function_exists( 'curl_init' ) ) {
- throw new MWException( __METHOD__.': curl (http://php.net/curl) is not installed, but $wgHTTPEngine is set to "curl"' );
+ if ( !Http::$httpEngine ) {
+ Http::$httpEngine = function_exists( 'curl_init' ) ? 'curl' : 'php';
+ } elseif ( Http::$httpEngine == 'curl' && !function_exists( 'curl_init' ) ) {
+ throw new MWException( __METHOD__.': curl (http://php.net/curl) is not installed, but Http::$httpEngine is set to "curl"' );
}
- switch( $wgHTTPEngine ) {
+ switch( Http::$httpEngine ) {
case 'curl':
return new CurlHttpRequest( $url, $options );
case 'php':
}
return new PhpHttpRequest( $url, $options );
default:
- throw new MWException( __METHOD__.': The setting of $wgHTTPEngine is not valid.' );
+ throw new MWException( __METHOD__.': The setting of Http::$httpEngine is not valid.' );
}
}
function testInstantiation() {
- global $wgHTTPEngine;
+ Http::$httpEngine = false;
- unset($wgHTTPEngine);
$r = new HttpRequest("http://www.example.com/");
if ( self::$has_curl ) {
$this->isInstanceOf( $r, 'CurlHttpRequest' );
}
unset($r);
- $wgHTTPEngine = 'php';
+ Http::$httpEngine = 'php';
$r = new HttpRequest("http://www.example.com/");
$this->isInstanceOf( $r, 'PhpHttpRequest' );
unset($r);
if( !self::$has_curl ) {
$this->setExpectedException( 'MWException' );
}
- $wgHTTPEngine = 'curl';
+ Http::$httpEngine = 'curl';
$r = new HttpRequest("http://www.example.com/");
if( self::$has_curl ) {
$this->isInstanceOf( $r, 'CurlHttpRequest' );
}
function runHTTPFailureChecks() {
- global $wgHTTPEngine;
// Each of the following requests should result in a failure.
$timeout = 1;
$r = HTTP::get( "http://www.example.com:1/", $timeout);
$end_time = time();
$this->assertLessThan($timeout+2, $end_time - $start_time,
- "Request took less than {$timeout}s via $wgHTTPEngine");
+ "Request took less than {$timeout}s via ".Http::$httpEngine);
$this->assertEquals($r, false, "false -- what we get on error from Http::get()");
}
function testFailureDefault() {
- global $wgHTTPEngine;
-
- unset($wgHTTPEngine);
+ Http::$httpEngine = false;
self::runHTTPFailureChecks();
}
function testFailurePhp() {
- global $wgHTTPEngine;
-
- $wgHTTPEngine = "php";
+ Http::$httpEngine = "php";
self::runHTTPFailureChecks();
}
function testFailureCurl() {
- global $wgHTTPEngine;
-
if (!self::$has_curl ) {
$this->markTestIncomplete("This test requires curl.");
}
- $wgHTTPEngine = "curl";
+ Http::$httpEngine = "curl";
self::runHTTPFailureChecks();
}
/* ./includes/Import.php:1124: $link = Title::newFromText( "$interwiki:Special:Export/$page" ); */
/* ./includes/Import.php:1134: return ImportStreamSource::newFromURL( $url, "POST" ); */
function runHTTPRequests($proxy=null) {
- global $wgHTTPEngine;
$opt = array();
if($proxy) {
/* no postData here because the only request I could find in code so far didn't have any */
foreach ( $this->test_requesturl as $u ) {
$r = Http::request( "POST", $u, $opt );
- $this->assertEquals( self::$content["POST $u"], "$r", "POST $u with $wgHTTPEngine" );
+ $this->assertEquals( self::$content["POST $u"], "$r", "POST $u with ".Http::$httpEngine );
}
}
function testRequestDefault() {
- global $wgHTTPEngine;
-
- unset($wgHTTPEngine);
+ Http::$httpEngine = false;
self::runHTTPRequests();
}
function testRequestPhp() {
- global $wgHTTPEngine;
-
- $wgHTTPEngine = "php";
+ Http::$httpEngine = "php";
self::runHTTPRequests();
}
function testRequestCurl() {
- global $wgHTTPEngine;
-
if (!self::$has_curl ) {
$this->markTestIncomplete("This test requires curl.");
}
- $wgHTTPEngine = "curl";
+ Http::$httpEngine = "curl";
self::runHTTPRequests();
}
/* ./extensions/Interlanguage/Interlanguage.php:56: $a = Http::get( $url ); */
/* ./extensions/MWSearch/MWSearch_body.php:492: $data = Http::get( $searchUrl, $wgLuceneSearchTimeout, $httpOpts); */
function runHTTPGets($proxy=null) {
- global $wgHTTPEngine;
$opt = array();
if($proxy) {
foreach ( $this->test_geturl as $u ) {
$r = Http::get( $u, 30, $opt ); /* timeout of 30s */
- $this->assertEquals( self::$content["GET $u"], "$r", "Get $u with $wgHTTPEngine" );
+ $this->assertEquals( self::$content["GET $u"], "$r", "Get $u with ".Http::$httpEngine );
}
}
function testGetDefault() {
- global $wgHTTPEngine;
-
- unset($wgHTTPEngine);
+ Http::$httpEngine = false;
self::runHTTPGets();
}
function testGetPhp() {
- global $wgHTTPEngine;
-
- $wgHTTPEngine = "php";
+ Http::$httpEngine = "php";
self::runHTTPGets();
}
function testGetCurl() {
- global $wgHTTPEngine;
-
if (!self::$has_curl ) {
$this->markTestIncomplete("This test requires curl.");
}
- $wgHTTPEngine = "curl";
+ Http::$httpEngine = "curl";
self::runHTTPGets();
}
/* ./phase3/maintenance/parserTests.inc:1618: return Http::post( $url, array( 'postData' => wfArrayToCGI( $data ) ) ); */
function runHTTPPosts($proxy=null) {
- global $wgHTTPEngine;
$opt = array();
if($proxy) {
$opt['postData'] = $postData;
$r = Http::post( $u, $opt );
$this->assertEquals( self::$content["POST $u => $postData"], "$r",
- "POST $u (postData=$postData) with $wgHTTPEngine" );
+ "POST $u (postData=$postData) with ".Http::$httpEngine );
}
}
function testPostDefault() {
- global $wgHTTPEngine;
-
- unset($wgHTTPEngine);
+ Http::$httpEngine = false;
self::runHTTPPosts();
}
function testPostPhp() {
- global $wgHTTPEngine;
-
- $wgHTTPEngine = "php";
+ Http::$httpEngine = "php";
self::runHTTPPosts();
}
function testPostCurl() {
- global $wgHTTPEngine;
-
if (!self::$has_curl ) {
$this->markTestIncomplete("This test requires curl.");
}
- $wgHTTPEngine = "curl";
+ Http::$httpEngine = "curl";
self::runHTTPPosts();
}
function runProxyRequests() {
- global $wgHTTPEngine;
-
if(!self::$has_proxy) {
$this->markTestIncomplete("This test requires a proxy.");
}
}
function testProxyDefault() {
- global $wgHTTPEngine;
-
- unset($wgHTTPEngine);
+ Http::$httpEngine = false;
self::runProxyRequests();
}
function testProxyPhp() {
- global $wgHTTPEngine;
-
- $wgHTTPEngine = 'php';
+ Http::$httpEngine = 'php';
self::runProxyRequests();
}
function testProxyCurl() {
- global $wgHTTPEngine;
-
if (!self::$has_curl ) {
$this->markTestIncomplete("This test requires curl.");
}
- $wgHTTPEngine = 'curl';
+ Http::$httpEngine = 'curl';
self::runProxyRequests();
}