aboutsummaryrefslogtreecommitdiffstats
path: root/includes/http/MWHttpRequest.php
diff options
context:
space:
mode:
authorPiotr Miazga <pmiazga@wikimedia.org>2024-05-04 18:04:36 +0300
committerJames D. Forrester <jforrester@wikimedia.org>2024-05-05 15:16:32 +0300
commit93867c106fd0b2b6aa96576b69e0666d9c1393c2 (patch)
treec4d440fe2a0b316ea66e761f4b905092d1db3df7 /includes/http/MWHttpRequest.php
parent0cd4b03b3189c3a925ef90c4a5d193c1da8eccb3 (diff)
downloadmediawikicore-93867c106fd0b2b6aa96576b69e0666d9c1393c2.tar.gz
mediawikicore-93867c106fd0b2b6aa96576b69e0666d9c1393c2.zip
MWHttpRequest: Drop support for creating without timeout or connectionTimeout, deprecated in 1.35
In 1.35 we deprecated not passing the timeout and connectionTimeout settings when constructing the MWHttpRequest object. Upgrade hard-deprecation via wfDeprecated() to instead throw an InvalidArgumentException. Change-Id: I260469c6235fa9022b264757b0a17d498cee1396
Diffstat (limited to 'includes/http/MWHttpRequest.php')
-rw-r--r--includes/http/MWHttpRequest.php30
1 files changed, 8 insertions, 22 deletions
diff --git a/includes/http/MWHttpRequest.php b/includes/http/MWHttpRequest.php
index 1f5080d5d530..dc228e9fc6c2 100644
--- a/includes/http/MWHttpRequest.php
+++ b/includes/http/MWHttpRequest.php
@@ -92,7 +92,7 @@ abstract class MWHttpRequest implements LoggerAwareInterface {
/**
* @param string $url Url to use. If protocol-relative, will be expanded to an http:// URL
- * @param array $options (optional) extra params to pass (see HttpRequestFactory::create())
+ * @param array $options extra params to pass (see HttpRequestFactory::create())
* @phpcs:ignore Generic.Files.LineLength
* @phan-param array{timeout?:int|string,connectTimeout?:int|string,postData?:array,proxy?:string,noProxy?:bool,sslVerifyHost?:bool,sslVerifyCert?:bool,caInfo?:string,maxRedirects?:int,followRedirects?:bool,userAgent?:string,logger?:LoggerInterface,username?:string,password?:string,originalRequest?:WebRequest|array{ip:string,userAgent:string},method?:string} $options
* @param string $caller The method making this request, for profiling
@@ -100,12 +100,18 @@ abstract class MWHttpRequest implements LoggerAwareInterface {
* @throws Exception
*/
public function __construct(
- $url, array $options = [], $caller = __METHOD__, Profiler $profiler = null
+ $url, array $options, $caller = __METHOD__, Profiler $profiler = null
) {
+ if ( !array_key_exists( 'timeout', $options )
+ || !array_key_exists( 'connectTimeout', $options ) ) {
+ throw new InvalidArgumentException( "timeout and connectionTimeout options are required" );
+ }
$this->url = wfExpandUrl( $url, PROTO_HTTP );
$this->parsedUrl = wfParseUrl( $this->url );
$this->logger = $options['logger'] ?? new NullLogger();
+ $this->timeout = $options['timeout'];
+ $this->connectTimeout = $options['connectTimeout'];
if ( !$this->parsedUrl || !self::isValidURI( $this->url ) ) {
$this->status = StatusValue::newFatal( 'http-invalid-url', $url );
@@ -113,26 +119,6 @@ abstract class MWHttpRequest implements LoggerAwareInterface {
$this->status = StatusValue::newGood( 100 ); // continue
}
- if ( isset( $options['timeout'] ) && $options['timeout'] != 'default' ) {
- $this->timeout = $options['timeout'];
- } else {
- // The timeout should always be set by HttpRequestFactory, so this
- // should only happen if the class was directly constructed
- wfDeprecated( __METHOD__ . ' without the timeout option', '1.35' );
- $httpTimeout = MediaWikiServices::getInstance()->getMainConfig()->get(
- MainConfigNames::HTTPTimeout );
- $this->timeout = $httpTimeout;
- }
- if ( isset( $options['connectTimeout'] ) && $options['connectTimeout'] != 'default' ) {
- $this->connectTimeout = $options['connectTimeout'];
- } else {
- // The timeout should always be set by HttpRequestFactory, so this
- // should only happen if the class was directly constructed
- wfDeprecated( __METHOD__ . ' without the connectTimeout option', '1.35' );
- $httpConnectTimeout = MediaWikiServices::getInstance()->getMainConfig()->get(
- MainConfigNames::HTTPConnectTimeout );
- $this->connectTimeout = $httpConnectTimeout;
- }
if ( isset( $options['userAgent'] ) ) {
$this->setUserAgent( $options['userAgent'] );
}