* @param string $method HTTP method. Usually GET/POST
* @param string $url Full URL to act on. If protocol-relative, will be expanded to an http:// URL
* @param array $options Options to pass to MWHttpRequest object.
- * Possible keys for the array:
+ * Possible keys for the array:
* - timeout Timeout length in seconds
* - connectTimeout Timeout for connection, in seconds (curl only)
* - postData An array of key-value pairs or a url-encoded form data
* @return string|bool (bool)false on failure or a string on success
*/
public static function request( $method, $url, $options = [], $caller = __METHOD__ ) {
- wfDebug( "HTTP: $method: $url\n" );
+ $logger = LoggerFactory::getInstance( 'http' );
+ $logger->debug( "$method: $url" );
$options['method'] = strtoupper( $method );
return $req->getContent();
} else {
$errors = $status->getErrorsByType( 'error' );
- $logger = LoggerFactory::getInstance( 'http' );
$logger->warning( Status::wrap( $status )->getWikiText( false, false, 'en' ),
[ 'error' => $errors, 'caller' => $caller, 'content' => $req->getContent() ] );
return false;
$options['timeout'] = $args[1];
$caller = __METHOD__;
}
- return Http::request( 'GET', $url, $options, $caller );
+ return self::request( 'GET', $url, $options, $caller );
}
/**
* @return string|bool false on error
*/
public static function post( $url, $options = [], $caller = __METHOD__ ) {
- return Http::request( 'POST', $url, $options, $caller );
+ return self::request( 'POST', $url, $options, $caller );
}
/**
return "";
}
+
+ /**
+ * Get a configured MultiHttpClient
+ * @param array $options
+ * @return MultiHttpClient
+ */
+ public static function createMultiClient( $options = [] ) {
+ global $wgHTTPConnectTimeout, $wgHTTPTimeout, $wgHTTPProxy;
+
+ return new MultiHttpClient( $options + [
+ 'connTimeout' => $wgHTTPConnectTimeout,
+ 'reqTimeout' => $wgHTTPTimeout,
+ 'userAgent' => self::userAgent(),
+ 'proxy' => $wgHTTPProxy,
+ 'logger' => LoggerFactory::getInstance( 'http' )
+ ] );
+ }
}