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