MediaWiki  master
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 }
wfWarn( $msg, $callerOffset=1, $level=E_USER_NOTICE)
Send a warning either to the debug log or in a PHP error depending on $wgDevelopmentWarnings.
static isValidURI( $uri)
Check that the given URI is a valid one.
static getProxy()
Gets the relevant proxy from $wgHTTPProxy.
Definition: Http.php:128
int $wgHTTPTimeout
Timeout for HTTP requests done internally, in seconds.
$wgHTTPProxy
Proxy to use for CURL requests.
static post( $url, array $options=[], $caller=__METHOD__)
Simple wrapper for Http::request( &#39;POST&#39; )
Definition: Http.php:88
static userAgent()
A standard user-agent we can use for external requests.
Definition: Http.php:98
static request( $method, $url, array $options=[], $caller=__METHOD__)
Perform an HTTP request.
Definition: Http.php:45
if( $line===false) $args
Definition: mcc.php:124
static $httpEngine
Definition: Http.php:31
Various HTTP related functions.
Definition: Http.php:29
static isValidURI( $uri)
Check that the given URI is a valid one.
Definition: Http.php:118
$wgHTTPConnectTimeout
Timeout for connections done internally (in seconds) Only works for curl.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
Class to handle multiple HTTP requests.
static createMultiClient(array $options=[])
Get a configured MultiHttpClient.
Definition: Http.php:142