* to avoid attacks on intranet services accessible by HTTP.
* - userAgent A user agent, if you want to override the default
* MediaWiki/$wgVersion
+ * @param string $caller The method making this request, for profiling
* @return string|bool (bool)false on failure or a string on success
*/
- public static function request( $method, $url, $options = array() ) {
+ public static function request( $method, $url, $options = array(), $caller = __METHOD__ ) {
wfDebug( "HTTP: $method: $url\n" );
$options['method'] = strtoupper( $method );
$options['connectTimeout'] = 'default';
}
- $req = MWHttpRequest::factory( $url, $options );
+ $req = MWHttpRequest::factory( $url, $options, $caller );
$status = $req->execute();
$content = false;
/**
* Simple wrapper for Http::request( 'GET' )
* @see Http::request()
+ * @since 1.25 Second parameter $timeout removed. Second parameter
+ * is now $options which can be given a 'timeout'
*
* @param string $url
- * @param string $timeout
* @param array $options
+ * @param string $caller The method making this request, for profiling
* @return string
*/
- public static function get( $url, $timeout = 'default', $options = array() ) {
- $options['timeout'] = $timeout;
- return Http::request( 'GET', $url, $options );
+ public static function get( $url, $options = array(), $caller = __METHOD__ ) {
+ $args = func_get_args();
+ if ( isset( $args[1] ) && ( is_string( $args[1] ) || is_numeric( $args[1] ) ) ) {
+ // Second was used to be the timeout
+ // And third parameter used to be $options
+ wfWarn( "Second parameter should not be a timeout.", 2 );
+ $options = isset( $args[2] ) && is_array( $args[2] ) ?
+ $args[2] : array();
+ $options['timeout'] = $args[1];
+ $caller = __METHOD__;
+ }
+ return Http::request( 'GET', $url, $options, $caller );
}
/**
*
* @param string $url
* @param array $options
+ * @param string $caller The method making this request, for profiling
* @return string
*/
- public static function post( $url, $options = array() ) {
- return Http::request( 'POST', $url, $options );
+ public static function post( $url, $options = array(), $caller = __METHOD__ ) {
+ return Http::request( 'POST', $url, $options, $caller );
}
/**
public $status;
+ /**
+ * @var Profiler
+ */
+ protected $profiler;
+
+ /**
+ * @var string
+ */
+ protected $profileName;
+
/**
* @param string $url Url to use. If protocol-relative, will be expanded to an http:// URL
* @param array $options (optional) extra params to pass (see Http::request())
+ * @param string $caller The method making this request, for profiling
+ * @param Profiler $profiler An instance of the profiler for profiling, or null
*/
- protected function __construct( $url, $options = array() ) {
+ protected function __construct( $url, $options = array(), $caller = __METHOD__, $profiler = null ) {
global $wgHTTPTimeout, $wgHTTPConnectTimeout;
$this->url = wfExpandUrl( $url, PROTO_HTTP );
if ( $this->noProxy ) {
$this->proxy = ''; // noProxy takes precedence
}
+
+ // Profile based on what's calling us
+ $this->profiler = $profiler;
+ $this->profileName = $caller;
}
/**
* Generate a new request object
* @param string $url Url to use
* @param array $options (optional) extra params to pass (see Http::request())
+ * @param string $caller The method making this request, for profiling
* @throws MWException
* @return CurlHttpRequest|PhpHttpRequest
* @see MWHttpRequest::__construct
*/
- public static function factory( $url, $options = null ) {
+ public static function factory( $url, $options = null, $caller = __METHOD__ ) {
if ( !Http::$httpEngine ) {
Http::$httpEngine = function_exists( 'curl_init' ) ? 'curl' : 'php';
} elseif ( Http::$httpEngine == 'curl' && !function_exists( 'curl_init' ) ) {
switch ( Http::$httpEngine ) {
case 'curl':
- return new CurlHttpRequest( $url, $options );
+ return new CurlHttpRequest( $url, $options, $caller, Profiler::instance() );
case 'php':
if ( !wfIniGetBool( 'allow_url_fopen' ) ) {
throw new MWException( __METHOD__ . ': allow_url_fopen ' .
'http://php.net/curl.'
);
}
- return new PhpHttpRequest( $url, $options );
+ return new PhpHttpRequest( $url, $options, $caller, Profiler::instance() );
default:
throw new MWException( __METHOD__ . ': The setting of Http::$httpEngine is not valid.' );
}
wfRestoreWarnings();
}
+ if ( $this->profiler ) {
+ $profileSection = $this->profiler->scopedProfileIn(
+ __METHOD__ . '-' . $this->profileName
+ );
+ }
+
$curlRes = curl_exec( $curlHandle );
if ( curl_errno( $curlHandle ) == CURLE_OPERATION_TIMEOUTED ) {
$this->status->fatal( 'http-timed-out', $this->url );
curl_close( $curlHandle );
+ if ( $this->profiler ) {
+ $this->profiler->scopedProfileOut( $profileSection );
+ }
+
$this->parseHeader();
$this->setStatus();
$result = array();
+ if ( $this->profiler ) {
+ $profileSection = $this->profiler->scopedProfileIn(
+ __METHOD__ . '-' . $this->profileName
+ );
+ }
do {
$reqCount++;
wfSuppressWarnings();
break;
}
} while ( true );
+ if ( $this->profiler ) {
+ $this->profiler->scopedProfileOut( $profileSection );
+ }
$this->setStatus();