MediaWiki  1.34.0
Http.php
Go to the documentation of this file.
1 <?php
23 
29 class Http {
31  public static $httpEngine = null;
32 
45  public static function request( $method, $url, array $options = [], $caller = __METHOD__ ) {
46  $ret = MediaWikiServices::getInstance()->getHttpRequestFactory()->request(
47  $method, $url, $options, $caller );
48  return is_string( $ret ) ? $ret : false;
49  }
50 
64  public static function get( $url, array $options = [], $caller = __METHOD__ ) {
65  $args = func_get_args();
66  if ( isset( $args[1] ) && ( is_string( $args[1] ) || is_numeric( $args[1] ) ) ) {
67  // Second was used to be the timeout
68  // And third parameter used to be $options
69  wfWarn( "Second parameter should not be a timeout.", 2 );
70  $options = isset( $args[2] ) && is_array( $args[2] ) ?
71  $args[2] : [];
72  $options['timeout'] = $args[1];
73  $caller = __METHOD__;
74  }
75  return self::request( 'GET', $url, $options, $caller );
76  }
77 
88  public static function post( $url, array $options = [], $caller = __METHOD__ ) {
89  return self::request( 'POST', $url, $options, $caller );
90  }
91 
98  public static function userAgent() {
99  return MediaWikiServices::getInstance()->getHttpRequestFactory()->getUserAgent();
100  }
101 
118  public static function isValidURI( $uri ) {
119  return MWHttpRequest::isValidURI( $uri );
120  }
121 
128  public static function getProxy() {
129  wfDeprecated( __METHOD__, '1.34' );
130 
131  global $wgHTTPProxy;
132  return (string)$wgHTTPProxy;
133  }
134 
142  public static function createMultiClient( array $options = [] ) {
143  wfDeprecated( __METHOD__, '1.34' );
144 
146 
147  return new MultiHttpClient( $options + [
148  'connTimeout' => $wgHTTPConnectTimeout,
149  'reqTimeout' => $wgHTTPTimeout,
150  'userAgent' => self::userAgent(),
151  'proxy' => $wgHTTPProxy,
152  'logger' => LoggerFactory::getInstance( 'http' )
153  ] );
154  }
155 }
$wgHTTPConnectTimeout
$wgHTTPConnectTimeout
Timeout for connections done internally (in seconds) Only works for curl.
Definition: DefaultSettings.php:8439
MultiHttpClient
Class to handle multiple HTTP requests.
Definition: MultiHttpClient.php:52
Http\$httpEngine
static $httpEngine
Definition: Http.php:31
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:117
Http\post
static post( $url, array $options=[], $caller=__METHOD__)
Simple wrapper for Http::request( 'POST' )
Definition: Http.php:88
Http\request
static request( $method, $url, array $options=[], $caller=__METHOD__)
Perform an HTTP request.
Definition: Http.php:45
Http\userAgent
static userAgent()
A standard user-agent we can use for external requests.
Definition: Http.php:98
$wgHTTPTimeout
int $wgHTTPTimeout
Timeout for HTTP requests done internally, in seconds.
Definition: DefaultSettings.php:8402
$wgHTTPProxy
$wgHTTPProxy
Proxy to use for CURL requests.
Definition: DefaultSettings.php:8418
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
Definition: GlobalFunctions.php:1044
MediaWiki\Logger\LoggerFactory
PSR-3 logger instance factory.
Definition: LoggerFactory.php:45
Http\getProxy
static getProxy()
Gets the relevant proxy from $wgHTTPProxy.
Definition: Http.php:128
Http\createMultiClient
static createMultiClient(array $options=[])
Get a configured MultiHttpClient.
Definition: Http.php:142
$args
if( $line===false) $args
Definition: cdb.php:64
MWHttpRequest\isValidURI
static isValidURI( $uri)
Check that the given URI is a valid one.
Definition: MWHttpRequest.php:689
Http\isValidURI
static isValidURI( $uri)
Check that the given URI is a valid one.
Definition: Http.php:118
wfWarn
wfWarn( $msg, $callerOffset=1, $level=E_USER_NOTICE)
Send a warning either to the debug log or in a PHP error depending on $wgDevelopmentWarnings.
Definition: GlobalFunctions.php:1065
Http
Various HTTP related functions.
Definition: Http.php:29