32use Psr\Log\LoggerInterface;
52 'HTTPMaxConnectTimeout',
102 if ( !isset(
$options[
'logger'] ) ) {
106 $options[
'timeout'] ??
null,
108 $this->options->
get(
'HTTPTimeout' ),
109 $this->options->get(
'HTTPMaxTimeout' )
112 $options[
'connectTimeout'] ??
null,
113 $options[
'maxConnectTimeout'] ??
null,
114 $this->options->
get(
'HTTPConnectTimeout' ),
115 $this->options->get(
'HTTPMaxConnectTimeout' )
126 throw new RuntimeException( __METHOD__ .
': The requested engine is not valid.' );
141 if ( $parameter ===
'default' || $parameter ===
null ) {
142 if ( !is_numeric( $default ) ) {
143 throw new \InvalidArgumentException(
144 '$wgHTTPTimeout and $wgHTTPConnectTimeout must be set to a number' );
150 if ( $maxParameter !==
null ) {
151 $max = $maxParameter;
153 $max = $maxConfigured;
155 if ( $max && $value > $max ) {
168 return function_exists(
'curl_init' ) ||
wfIniGetBool(
'allow_url_fopen' );
183 $logger = LoggerFactory::getInstance(
'http' );
184 $logger->debug(
"$method: $url" );
186 $options[
'method'] = strtoupper( $method );
189 $status = $req->execute();
191 if ( $status->isOK() ) {
192 return $req->getContent();
194 $errors = $status->getErrorsByType(
'error' );
195 $logger->warning( Status::wrap( $status )->getWikiText(
false,
false,
'en' ),
196 [
'error' => $errors,
'caller' => $caller,
'content' => $req->getContent() ] );
210 public function get( $url, array
$options = [], $caller = __METHOD__ ) {
223 public function post( $url, array
$options = [], $caller = __METHOD__ ) {
248 $options[
'reqTimeout'] ??
$options[
'timeout'] ??
null,
250 $this->options->
get(
'HTTPTimeout' ),
251 $this->options->get(
'HTTPMaxTimeout' )
254 $options[
'connTimeout'] ??
$options[
'connectTimeout'] ??
null,
256 $this->options->
get(
'HTTPConnectTimeout' ),
257 $this->options->get(
'HTTPMaxConnectTimeout' )
260 'maxReqTimeout' => $this->options->get(
'HTTPMaxTimeout' ),
261 'maxConnTimeout' => $this->options->get(
'HTTPMaxConnectTimeout' ),
265 return new MultiHttpClient(
$options );
283 $config[
'timeout'] ?? null,
284 $config[
'maxTimeout'] ?? null,
285 $this->options->
get(
'HTTPTimeout' ),
286 $this->options->
get(
'HTTPMaxTimeout' )
290 $config[
'connect_timeout'] ??
null,
291 $config[
'maxConnectTimeout'] ??
null,
292 $this->options->get(
'HTTPConnectTimeout' ),
293 $this->options->get(
'HTTPMaxConnectTimeout' )
296 if ( !isset( $config[
'headers'][
'User-Agent'] ) ) {
297 $config[
'headers'][
'User-Agent'] = $this->
getUserAgent();
300 return new Client( $config );
const MW_VERSION
The running version of MediaWiki.
wfIniGetBool( $setting)
Safety wrapper around ini_get() for boolean settings.
MWHttpRequest implemented using internal curl compiled into PHP.
MWHttpRequest implemented using the Guzzle library.
Various HTTP related functions.
This wrapper class will call out to curl (if available) or fallback to regular PHP if necessary for h...
Class to handle multiple HTTP requests.
Profiler base class that defines the interface and some shared functionality.
static instance()
Singleton.
Generic operation result class Has warning/error list, boolean status and arbitrary value.