MediaWiki  1.27.0
Http Class Reference

Various HTTP related functions. More...

Static Public Member Functions

static get ($url, $options=[], $caller=__METHOD__)
 Simple wrapper for Http::request( 'GET' ) More...
 
static getProxy ()
 Gets the relevant proxy from $wgHTTPProxy/http_proxy (when set). More...
 
static isLocalURL ($url)
 Check if the URL can be served by localhost. More...
 
static isValidURI ($uri)
 Checks that the given URI is a valid one. More...
 
static post ($url, $options=[], $caller=__METHOD__)
 Simple wrapper for Http::request( 'POST' ) More...
 
static request ($method, $url, $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 34 of file HttpFunctions.php.

Member Function Documentation

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

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

See also
Http::request()
Since
1.25 Second parameter $timeout removed. Second parameter is now $options which can be given a 'timeout'
Parameters
string$url
array$options
string$callerThe method making this request, for profiling
Returns
string|bool false on error

Definition at line 100 of file HttpFunctions.php.

References $args, request(), and wfWarn().

Referenced by Installer\dirIsExecutable(), BenchHttpHttps\doRequest(), WikiRevision\downloadSource(), ImportSiteScripts\execute(), ExternalStoreHttp\fetchFromURL(), ImportSiteScripts\fetchScriptList(), ForeignDBFile\getDescriptionText(), File\getDescriptionText(), getFileCommentFromSourceWiki(), getFileUserFromSourceWiki(), FindHooks\getHooksFromOnlineDocCategory(), MediaWiki\Site\MediaWikiPageNameNormalizer\normalizePageName(), and MediaWikiPageNameNormalizerTest\setUp().

static Http::getProxy ( )
static

Gets the relevant proxy from $wgHTTPProxy/http_proxy (when set).

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

Definition at line 201 of file HttpFunctions.php.

References global.

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

static Http::isLocalURL (   $url)
static

Check if the URL can be served by localhost.

Parameters
string$urlFull url to check
Returns
bool

Definition at line 133 of file HttpFunctions.php.

References $matches, $wgCommandLineMode, and global.

Referenced by MWHttpRequest\proxySetup().

static Http::isValidURI (   $uri)
static

Checks that the given URI is a valid one.

Hardcoding the protocols, because we only want protocols that both cURL and php support.

file:// should not be allowed here for security purpose (r67684)

Todo:
FIXME this is wildly inaccurate and fails to actually check most stuff
Parameters
string$uriURI to check for validity
Returns
bool

Definition at line 189 of file HttpFunctions.php.

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

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

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

See also
Http::request()
Parameters
string$url
array$options
string$callerThe method making this request, for profiling
Returns
string|bool false on error

Definition at line 123 of file HttpFunctions.php.

References request().

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

Perform an HTTP request.

Parameters
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
string$callerThe method making this request, for profiling
Returns
string|bool (bool)false on failure or a string on success

Definition at line 63 of file HttpFunctions.php.

References $options, $req, $status, MWHttpRequest\factory(), and wfDebug().

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

static Http::userAgent ( )
static

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

Returns
string

Definition at line 172 of file HttpFunctions.php.

References $wgVersion, and global.

Referenced by MWHttpRequest\execute(), ForeignAPIRepo\getUserAgent(), and SquidPurgeClient\queuePurge().

Member Data Documentation

Http::$httpEngine = false
static

Definition at line 35 of file HttpFunctions.php.

Referenced by MWHttpRequest\factory(), and MWHttpRequestTester\factory().


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