MediaWiki  1.33.0
Http Class Reference

Various HTTP related functions. More...

Inheritance diagram for Http:

Static Public Member Functions

static createMultiClient (array $options=[])
 Get a configured MultiHttpClient. More...
static get ( $url, array $options=[], $caller=__METHOD__)
 Simple wrapper for Http::request( 'GET' ) More...
static getProxy ()
 Gets the relevant proxy from $wgHTTPProxy. More...
static isValidURI ( $uri)
 Check that the given URI is a valid one. More...
static post ( $url, array $options=[], $caller=__METHOD__)
 Simple wrapper for Http::request( 'POST' ) More...
static request ( $method, $url, array $options=[], $caller=__METHOD__)
 Perform an HTTP request. More...
static userAgent ()
 A standard user-agent we can use for external requests. More...

Static Public Attributes

static $httpEngine = false

Detailed Description

Various HTTP related functions.

Definition at line 27 of file Http.php.

Member Function Documentation

◆ createMultiClient()

static Http::createMultiClient ( array  $options = [])

Get a configured MultiHttpClient.


Definition at line 176 of file Http.php.

References $options, $wgHTTPConnectTimeout, $wgHTTPProxy, and $wgHTTPTimeout.

◆ get()

static Http::get (   $url,
array  $options = [],
  $caller = __METHOD__ 

◆ getProxy()

static Http::getProxy ( )

Gets the relevant proxy from $wgHTTPProxy.

mixed The proxy address or an empty string if not set.

Definition at line 161 of file Http.php.

References $wgHTTPProxy.

Referenced by MWHttpRequest\proxySetup(), and HttpTest\testGetProxy().

◆ isValidURI()

static Http::isValidURI (   $uri)

Check that the given URI is a valid one.

This hardcodes a small set of protocols only, because we want to deterministically reject protocols not supported by all HTTP-transport methods.

"file://" specifically must not be allowed, for security purpose (see

FIXME this is wildly inaccurate and fails to actually check most stuff
string$uriURI to check for validity

Definition at line 149 of file Http.php.

Referenced by MWHttpRequest\__construct(), PhpHttpRequest\execute(), UploadFromUrl\fetchFile(), SideBarTest\initMessagesHref(), and HttpTest\testIsValidUri().

◆ post()

static Http::post (   $url,
array  $options = [],
  $caller = __METHOD__ 

Simple wrapper for Http::request( 'POST' )

See also
string$callerThe method making this request, for profiling
string|bool false on error

Definition at line 121 of file Http.php.

References $options, and request().

Referenced by Pingback\postPingback().

◆ request()

static Http::request (   $method,
array  $options = [],
  $caller = __METHOD__ 

Perform an HTTP request.

string$methodHTTP method. Usually GET/POST
string$urlFull URL to act on. If protocol-relative, will be expanded to an http:// URL
array$optionsOptions to pass to MWHttpRequest object. 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
  • proxy The proxy to use. Otherwise it will use $wgHTTPProxy (if set) Otherwise it will use the environment variable "http_proxy" (if set)
  • noProxy Don't use any proxy at all. Takes precedence over proxy value(s).
  • sslVerifyHost Verify hostname against certificate
  • sslVerifyCert Verify SSL certificate
  • caInfo Provide CA information
  • maxRedirects Maximum number of redirects to follow (defaults to 5)
  • followRedirects Whether to follow redirects (defaults to false). Note: this should only be used when the target URL is trusted, to avoid attacks on intranet services accessible by HTTP.
  • userAgent A user agent, if you want to override the default MediaWiki/$wgVersion
  • logger A \Psr\Logger\LoggerInterface instance for debug logging
  • username Username for HTTP Basic Authentication
  • password Password for HTTP Basic Authentication
  • originalRequest Information about the original request (as a WebRequest object or an associative array with 'ip' and 'userAgent').
string$callerThe method making this request, for profiling
string|bool (bool)false on failure or a string on success

Definition at line 61 of file Http.php.

References $options, $req, MWHttpRequest\factory(), and Status\wrap().

Referenced by FileBackendTest\doTestGetFileHttpUrl(), get(), ImportStreamSource\newFromURL(), and post().

◆ userAgent()

static Http::userAgent ( )

A standard user-agent we can use for external requests.


Definition at line 129 of file Http.php.

References $wgVersion.

Referenced by MediaWiki\Sparql\SparqlClient\__construct(), ForeignAPIRepo\getUserAgent(), MediaWiki\Sparql\SparqlClientTest\optionsProvider(), MWHttpRequest\prepare(), and SquidPurgeClient\queuePurge().

Member Data Documentation

◆ $httpEngine

The documentation for this class was generated from the following file: