MediaWiki REL1_37
MediaWiki\Http\HttpRequestFactory Class Reference

Factory creating MWHttpRequest objects. More...

Collaboration diagram for MediaWiki\Http\HttpRequestFactory:

Public Member Functions

 __construct (ServiceOptions $options, LoggerInterface $logger)
 
 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 same meaning as for request()
 
 getUserAgent ()
 
 post ( $url, array $options=[], $caller=__METHOD__)
 Simple wrapper for request( 'POST' ), parameters have same meaning as for request()
 
 request ( $method, $url, array $options=[], $caller=__METHOD__)
 Perform an HTTP request.
 

Public Attributes

const CONSTRUCTOR_OPTIONS
 

Private Member Functions

 normalizeTimeout ( $parameter, $maxParameter, $default, $maxConfigured)
 Given a passed parameter value, a default and a maximum, figure out the correct timeout to pass to the backend.
 

Private Attributes

LoggerInterface $logger
 
ServiceOptions $options
 

Detailed Description

Factory creating MWHttpRequest objects.

Definition at line 39 of file HttpRequestFactory.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Http\HttpRequestFactory::__construct ( ServiceOptions  $options,
LoggerInterface  $logger 
)

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 167 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 (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
Exceptions
RuntimeException
Returns
MWHttpRequest
See also
MWHttpRequest::__construct

Definition at line 97 of file HttpRequestFactory.php.

References Http\$httpEngine, MediaWiki\Http\HttpRequestFactory\$logger, MediaWiki\Http\HttpRequestFactory\$options, MediaWiki\Config\ServiceOptions\get(), Profiler\instance(), and MediaWiki\Http\HttpRequestFactory\normalizeTimeout().

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 281 of file HttpRequestFactory.php.

◆ 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 246 of file HttpRequestFactory.php.

References MediaWiki\Http\HttpRequestFactory\$logger, MediaWiki\Http\HttpRequestFactory\$options, MediaWiki\Config\ServiceOptions\get(), MediaWiki\Http\HttpRequestFactory\getUserAgent(), and MediaWiki\Http\HttpRequestFactory\normalizeTimeout().

◆ get()

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

Simple wrapper for request( 'GET' ), parameters have same meaning as for request()

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

Definition at line 210 of file HttpRequestFactory.php.

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

◆ getUserAgent()

MediaWiki\Http\HttpRequestFactory::getUserAgent ( )

◆ normalizeTimeout()

MediaWiki\Http\HttpRequestFactory::normalizeTimeout (   $parameter,
  $maxParameter,
  $default,
  $maxConfigured 
)
private

Given a passed parameter value, a default and a maximum, figure out the correct timeout to pass to the backend.

Parameters
int | float | string | null$parameterThe timeout in seconds, or "default" or null
int | float | null$maxParameterThe maximum timeout specified by the caller
int | float$defaultThe configured default timeout
int | float$maxConfiguredThe configured maximum timeout
Returns
int|float

Definition at line 140 of file HttpRequestFactory.php.

Referenced by MediaWiki\Http\HttpRequestFactory\create(), and MediaWiki\Http\HttpRequestFactory\createMultiClient().

◆ post()

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

Simple wrapper for request( 'POST' ), parameters have same meaning as for request()

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

Definition at line 223 of file HttpRequestFactory.php.

References MediaWiki\Http\HttpRequestFactory\$options, 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 182 of file HttpRequestFactory.php.

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

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

Member Data Documentation

◆ $logger

◆ $options

◆ CONSTRUCTOR_OPTIONS

const MediaWiki\Http\HttpRequestFactory::CONSTRUCTOR_OPTIONS
Initial value:
= [
'HTTPTimeout',
'HTTPConnectTimeout',
'HTTPMaxTimeout',
'HTTPMaxConnectTimeout',
]
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: