MediaWiki master
MediaWiki\Http\HttpRequestFactory Class Reference

Factory creating MWHttpRequest objects. More...

Public Member Functions

 __construct (ServiceOptions $options, LoggerInterface $logger, ?Telemetry $telemetry=null)
 
 canMakeRequests ()
 Simple function to test if we can make any sort of requests at all, using cURL or fopen()
 
 create ( $url, array $options=[], $caller=__METHOD__)
 Generate a new MWHttpRequest object.
 
 createGuzzleClient (array $config=[])
 Get a GuzzleHttp\Client instance.
 
 createMultiClient ( $options=[])
 Get a MultiHttpClient with MediaWiki configured defaults applied.
 
 get ( $url, array $options=[], $caller=__METHOD__)
 Simple wrapper for ‘request( 'GET’ ), parameters have the same meaning as forrequest()`.
 
 getUserAgent ()
 
 post ( $url, array $options=[], $caller=__METHOD__)
 Simple wrapper for ‘request( 'POST’ ), parameters have the same meaning as forrequest()`.
 
 request ( $method, $url, array $options=[], $caller=__METHOD__)
 Perform an HTTP request.
 

Public Attributes

const CONSTRUCTOR_OPTIONS
 

Detailed Description

Factory creating MWHttpRequest objects.

Definition at line 37 of file HttpRequestFactory.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Http\HttpRequestFactory::__construct ( ServiceOptions $options,
LoggerInterface $logger,
?Telemetry $telemetry = null )

Member Function Documentation

◆ canMakeRequests()

MediaWiki\Http\HttpRequestFactory::canMakeRequests ( )

Simple function to test if we can make any sort of requests at all, using cURL or fopen()

Returns
bool

Definition at line 159 of file HttpRequestFactory.php.

References wfIniGetBool().

◆ create()

MediaWiki\Http\HttpRequestFactory::create ( $url,
array $options = [],
$caller = __METHOD__ )

Generate a new MWHttpRequest object.

Parameters
string$urlUrl to use
array$optionsPossible keys for the array:
  • timeout Timeout length in seconds or 'default'
  • connectTimeout Timeout for connection, in seconds (curl only) or 'default'
  • maxTimeout Override for the configured maximum timeout. This should not be used in production code.
  • maxConnectTimeout Override for the configured maximum connect timeout. This should not be used in production code.
  • postData An array of key-value pairs or a url-encoded form data
  • proxy The proxy to use. Otherwise it will use $wgHTTPProxy or $wgLocalHTTPProxy (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/{MW_VERSION}".
  • 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'). @phpcs:ignore Generic.Files.LineLength
string$callerThe method making this request, for profiling
Returns
MWHttpRequest
See also
MWHttpRequest::__construct

Definition at line 103 of file HttpRequestFactory.php.

References $url, MediaWiki\Config\ServiceOptions\get(), MediaWiki\MainConfigNames\HTTPConnectTimeout, MediaWiki\MainConfigNames\HTTPMaxConnectTimeout, MediaWiki\MainConfigNames\HTTPMaxTimeout, MediaWiki\MainConfigNames\HTTPTimeout, and Profiler\instance().

Referenced by MediaWiki\Http\HttpRequestFactory\request().

◆ createGuzzleClient()

MediaWiki\Http\HttpRequestFactory::createGuzzleClient ( array $config = [])

Get a GuzzleHttp\Client instance.

Since
1.36
Parameters
array$configClient configuration settings.
Returns
Client
See also
\GuzzleHttp\RequestOptions for a list of available request options.
Client::__construct() for additional options. Additional options that should not be used in production code:
  • maxTimeout Override for the configured maximum timeout.
  • maxConnectTimeout Override for the configured maximum connect timeout.

Definition at line 277 of file HttpRequestFactory.php.

References MediaWiki\Http\HttpRequestFactory\getUserAgent().

◆ createMultiClient()

MediaWiki\Http\HttpRequestFactory::createMultiClient ( $options = [])

Get a MultiHttpClient with MediaWiki configured defaults applied.

Unlike create(), by default, no proxy will be used. To use a proxy, specify the 'proxy' option.

Parameters
array$optionsOptions as documented in MultiHttpClient::__construct(), except that for consistency with create(), 'timeout' is accepted as an alias for 'reqTimeout', and 'connectTimeout' is accepted as an alias for 'connTimeout'.
Returns
MultiHttpClient

Definition at line 238 of file HttpRequestFactory.php.

References MediaWiki\Http\Telemetry\getInstance(), MediaWiki\Http\HttpRequestFactory\getUserAgent(), MediaWiki\MainConfigNames\HTTPConnectTimeout, MediaWiki\MainConfigNames\HTTPMaxConnectTimeout, MediaWiki\MainConfigNames\HTTPMaxTimeout, MediaWiki\MainConfigNames\HTTPTimeout, MediaWiki\MainConfigNames\LocalHTTPProxy, and MediaWiki\MainConfigNames\LocalVirtualHosts.

◆ get()

MediaWiki\Http\HttpRequestFactory::get ( $url,
array $options = [],
$caller = __METHOD__ )

Simple wrapper for ‘request( 'GET’ ), parameters have the same meaning as forrequest()`.

Since
1.34
Parameters
string$url
array$options
string$caller
Returns
string|null

Definition at line 202 of file HttpRequestFactory.php.

References $url, and MediaWiki\Http\HttpRequestFactory\request().

◆ getUserAgent()

MediaWiki\Http\HttpRequestFactory::getUserAgent ( )

◆ post()

MediaWiki\Http\HttpRequestFactory::post ( $url,
array $options = [],
$caller = __METHOD__ )

Simple wrapper for ‘request( 'POST’ ), parameters have the same meaning as forrequest()`.

Since
1.34
Parameters
string$url
array$options
string$caller
Returns
string|null

Definition at line 215 of file HttpRequestFactory.php.

References $url, and MediaWiki\Http\HttpRequestFactory\request().

◆ request()

MediaWiki\Http\HttpRequestFactory::request ( $method,
$url,
array $options = [],
$caller = __METHOD__ )

Perform an HTTP request.

Since
1.34
Parameters
string$methodHTTP method. Usually GET/POST
string$urlFull URL to act on. If protocol-relative, will be expanded to an http:// URL
array$optionsSee HttpRequestFactory::create
string$callerThe method making this request, for profiling
Returns
string|null null on failure or a string on success

Definition at line 174 of file HttpRequestFactory.php.

References $url, and MediaWiki\Http\HttpRequestFactory\create().

Referenced by MediaWiki\Http\HttpRequestFactory\get(), and MediaWiki\Http\HttpRequestFactory\post().

Member Data Documentation

◆ CONSTRUCTOR_OPTIONS

const MediaWiki\Http\HttpRequestFactory::CONSTRUCTOR_OPTIONS
Initial value:
= [
]
const HTTPConnectTimeout
Name constant for the HTTPConnectTimeout setting, for use with Config::get()
const HTTPTimeout
Name constant for the HTTPTimeout setting, for use with Config::get()
const LocalVirtualHosts
Name constant for the LocalVirtualHosts setting, for use with Config::get()
const HTTPMaxConnectTimeout
Name constant for the HTTPMaxConnectTimeout setting, for use with Config::get()
const HTTPMaxTimeout
Name constant for the HTTPMaxTimeout setting, for use with Config::get()
const LocalHTTPProxy
Name constant for the LocalHTTPProxy setting, for use with Config::get()
Access: internal
For use by ServiceWiring

Definition at line 48 of file HttpRequestFactory.php.


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