Remove deprecated class Http
The class and all functions are deprecated: - Http::request() - Http::get() - Http::post() - Http::userAgent() - Http::isValidURI() - Http::getProxy() - Http::createMultiClient() Bug: T305813 Change-Id: Icd8af4822b16b4bf4558b756e20171c3ae9a9fa1
This commit is contained in:
parent
4bd94b22e3
commit
4a1479c9cc
5 changed files with 3 additions and 277 deletions
|
|
@ -85,6 +85,9 @@ because of Phabricator reports.
|
|||
* Article::getRedirectHeaderHtml() no longer accepts an array as $target.
|
||||
Passing an array was deprecated in 1.39.
|
||||
* IDatabase::wasErrorReissuable(), deprecated since 1.40, has been removed.
|
||||
* The Http class, deprecated since 1.34, with the functions ::request(),
|
||||
::get(), ::post(), ::userAgent(), ::isValidURI(), ::getProxy(),
|
||||
::createMultiClient() have been removed.
|
||||
* The following unused IDatabase methods were removed without deprecation:
|
||||
- ::wasLockTimeout()
|
||||
- ::wasConnectionLoss()
|
||||
|
|
|
|||
|
|
@ -622,7 +622,6 @@ $wgAutoloadLocalClasses = [
|
|||
'HtmlArmor' => __DIR__ . '/includes/libs/HtmlArmor.php',
|
||||
'HtmlCacheUpdater' => __DIR__ . '/includes/cache/HtmlCacheUpdater.php',
|
||||
'HtmlFileCacheUpdate' => __DIR__ . '/includes/deferred/HtmlFileCacheUpdate.php',
|
||||
'Http' => __DIR__ . '/includes/http/Http.php',
|
||||
'HttpError' => __DIR__ . '/includes/exception/HttpError.php',
|
||||
'HttpStatus' => __DIR__ . '/includes/libs/HttpStatus.php',
|
||||
'IApiMessage' => __DIR__ . '/includes/api/IApiMessage.php',
|
||||
|
|
|
|||
|
|
@ -1,152 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
* http://www.gnu.org/copyleft/gpl.html
|
||||
*
|
||||
* @file
|
||||
*/
|
||||
|
||||
use MediaWiki\MainConfigNames;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
|
||||
/**
|
||||
* Various HTTP related functions
|
||||
* @deprecated since 1.34
|
||||
* @ingroup HTTP
|
||||
*/
|
||||
class Http {
|
||||
/**
|
||||
* Perform an HTTP request
|
||||
*
|
||||
* @deprecated since 1.34, use HttpRequestFactory::request(). Hard-deprecated since 1.40.
|
||||
*
|
||||
* @param string $method HTTP method. Usually GET/POST
|
||||
* @param string $url Full URL to act on. If protocol-relative, will be expanded to an http:// URL
|
||||
* @param array $options Options to pass to MWHttpRequest object. See HttpRequestFactory::create
|
||||
* docs
|
||||
* @param string $caller The method making this request, for profiling
|
||||
* @return string|false
|
||||
*/
|
||||
public static function request( $method, $url, array $options = [], $caller = __METHOD__ ) {
|
||||
wfDeprecated( __METHOD__, '1.34' );
|
||||
$ret = MediaWikiServices::getInstance()->getHttpRequestFactory()->request(
|
||||
$method, $url, $options, $caller );
|
||||
return is_string( $ret ) ? $ret : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple wrapper for Http::request( 'GET' )
|
||||
*
|
||||
* @deprecated since 1.34, use HttpRequestFactory::get(). Hard-deprecated since 1.40.
|
||||
*
|
||||
* @since 1.25 Second parameter $timeout removed. Second parameter
|
||||
* is now $options which can be given a 'timeout'
|
||||
*
|
||||
* @param string $url
|
||||
* @param array $options
|
||||
* @param string $caller The method making this request, for profiling
|
||||
* @return string|false false on error
|
||||
*/
|
||||
public static function get( $url, array $options = [], $caller = __METHOD__ ) {
|
||||
wfDeprecated( __METHOD__, '1.34' );
|
||||
$args = func_get_args();
|
||||
if ( isset( $args[1] ) && ( is_string( $args[1] ) || is_numeric( $args[1] ) ) ) {
|
||||
// Second was used to be the timeout
|
||||
// And third parameter used to be $options
|
||||
wfWarn( "Second parameter should not be a timeout.", 2 );
|
||||
$options = isset( $args[2] ) && is_array( $args[2] ) ?
|
||||
$args[2] : [];
|
||||
$options['timeout'] = $args[1];
|
||||
$caller = __METHOD__;
|
||||
}
|
||||
return self::request( 'GET', $url, $options, $caller );
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple wrapper for Http::request( 'POST' )
|
||||
*
|
||||
* @deprecated since 1.34, use HttpRequestFactory::post(). Hard-deprecated since 1.40.
|
||||
*
|
||||
* @param string $url
|
||||
* @param array $options
|
||||
* @param string $caller The method making this request, for profiling
|
||||
* @return string|false false on error
|
||||
*/
|
||||
public static function post( $url, array $options = [], $caller = __METHOD__ ) {
|
||||
wfDeprecated( __METHOD__, '1.34' );
|
||||
return self::request( 'POST', $url, $options, $caller );
|
||||
}
|
||||
|
||||
/**
|
||||
* A standard user-agent we can use for external requests.
|
||||
*
|
||||
* @deprecated since 1.34, use HttpRequestFactory::getUserAgent(). Hard-deprecated since 1.40.
|
||||
* @return string
|
||||
*/
|
||||
public static function userAgent() {
|
||||
wfDeprecated( __METHOD__, '1.34' );
|
||||
return MediaWikiServices::getInstance()->getHttpRequestFactory()->getUserAgent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that the given URI is a valid one.
|
||||
*
|
||||
* This hardcodes a small set of protocols only, because we want to
|
||||
* deterministically reject protocols not supported by all HTTP-transport
|
||||
* methods.
|
||||
*
|
||||
* "file://" specifically must not be allowed, for security purpose
|
||||
* (see <https://www.mediawiki.org/wiki/Special:Code/MediaWiki/r67684>).
|
||||
*
|
||||
* @todo FIXME this is wildly inaccurate and fails to actually check most stuff
|
||||
*
|
||||
* @deprecated since 1.34, use MWHttpRequest::isValidURI. Hard-deprecated since 1.40.
|
||||
* @param string $uri URI to check for validity
|
||||
* @return bool
|
||||
*/
|
||||
public static function isValidURI( $uri ) {
|
||||
wfDeprecated( __METHOD__, '1.34' );
|
||||
return MWHttpRequest::isValidURI( $uri );
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the relevant proxy from $wgHTTPProxy
|
||||
*
|
||||
* @deprecated since 1.34, use $wgHTTPProxy directly
|
||||
* @return string The proxy address or an empty string if not set.
|
||||
*/
|
||||
public static function getProxy() {
|
||||
wfDeprecated( __METHOD__, '1.34' );
|
||||
|
||||
$httpProxy = MediaWikiServices::getInstance()->getMainConfig()->get(
|
||||
MainConfigNames::HTTPProxy );
|
||||
return (string)$httpProxy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a configured MultiHttpClient
|
||||
*
|
||||
* @deprecated since 1.34, use MediaWikiServices::getHttpRequestFactory()->createMultiClient()
|
||||
* @param array $options
|
||||
* @return MultiHttpClient
|
||||
*/
|
||||
public static function createMultiClient( array $options = [] ) {
|
||||
wfDeprecated( __METHOD__, '1.34' );
|
||||
$httpProxy = MediaWikiServices::getInstance()->getMainConfig()->get(
|
||||
MainConfigNames::HTTPProxy );
|
||||
return MediaWikiServices::getInstance()->getHttpRequestFactory()
|
||||
->createMultiClient( $options + [ 'proxy' => $httpProxy ] );
|
||||
}
|
||||
}
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
<?php
|
||||
|
||||
use MediaWiki\MainConfigNames;
|
||||
|
||||
/**
|
||||
* @covers Http
|
||||
* @group Http
|
||||
* @group small
|
||||
*/
|
||||
class HttpTest extends MediaWikiIntegrationTestCase {
|
||||
|
||||
/**
|
||||
* @covers Http::getProxy
|
||||
*/
|
||||
public function testGetProxy() {
|
||||
$this->hideDeprecated( 'Http::getProxy' );
|
||||
|
||||
$this->overrideConfigValue( MainConfigNames::HTTPProxy, false );
|
||||
$this->assertSame(
|
||||
'',
|
||||
Http::getProxy(),
|
||||
'default setting'
|
||||
);
|
||||
|
||||
$this->overrideConfigValue( MainConfigNames::HTTPProxy, 'proxy.domain.tld' );
|
||||
$this->assertEquals(
|
||||
'proxy.domain.tld',
|
||||
Http::getProxy()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,92 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @covers Http
|
||||
* @group Http
|
||||
* @group small
|
||||
*/
|
||||
class HttpUnitTest extends MediaWikiUnitTestCase {
|
||||
|
||||
/**
|
||||
* Test Http::isValidURI()
|
||||
* T29854 : Http::isValidURI is too lax
|
||||
* @dataProvider provideURI
|
||||
* @covers Http::isValidURI
|
||||
*/
|
||||
public function testIsValidUri( $expect, $URI, $message = '' ) {
|
||||
$this->hideDeprecated( 'Http::isValidURI' );
|
||||
$this->assertEquals(
|
||||
$expect,
|
||||
(bool)Http::isValidURI( $URI ),
|
||||
$message
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Feeds URI to test a long regular expression in Http::isValidURI
|
||||
*/
|
||||
public static function provideURI() {
|
||||
/** Format: 'boolean expectation', 'URI to test', 'Optional message' */
|
||||
return [
|
||||
[ false, '¿non sens before!! http://a', 'Allow anything before URI' ],
|
||||
|
||||
# (http|https) - only two schemes allowed
|
||||
[ true, 'http://www.example.org/' ],
|
||||
[ true, 'https://www.example.org/' ],
|
||||
[ true, 'http://www.example.org', 'URI without directory' ],
|
||||
[ true, 'http://a', 'Short name' ],
|
||||
[ true, 'http://étoile', 'Allow UTF-8 in hostname' ], # 'étoile' is french for 'star'
|
||||
[ false, '\\host\directory', 'CIFS share' ],
|
||||
[ false, 'gopher://host/dir', 'Reject gopher scheme' ],
|
||||
[ false, 'telnet://host', 'Reject telnet scheme' ],
|
||||
|
||||
# :\/\/ - double slashes
|
||||
[ false, 'http//example.org', 'Reject missing colon in protocol' ],
|
||||
[ false, 'http:/example.org', 'Reject missing slash in protocol' ],
|
||||
[ false, 'http:example.org', 'Must have two slashes' ],
|
||||
# Following fail since hostname can be made of anything
|
||||
[ false, 'http:///example.org', 'Must have exactly two slashes, not three' ],
|
||||
|
||||
# (\w+:{0,1}\w*@)? - optional user:pass
|
||||
[ true, 'http://user@host', 'Username provided' ],
|
||||
[ true, 'http://user:@host', 'Username provided, no password' ],
|
||||
[ true, 'http://user:pass@host', 'Username and password provided' ],
|
||||
|
||||
# (\S+) - host part is made of anything not whitespaces
|
||||
// commented these out in order to remove @group Broken
|
||||
// @todo are these valid tests? if so, fix Http::isValidURI so it can handle them
|
||||
// [ false, 'http://!"èèè¿¿¿~~\'', 'hostname is made of any non whitespace' ],
|
||||
// [ false, 'http://exam:ple.org/', 'hostname can not use colons!' ],
|
||||
|
||||
# (:[0-9]+)? - port number
|
||||
[ true, 'http://example.org:80/' ],
|
||||
[ true, 'https://example.org:80/' ],
|
||||
[ true, 'http://example.org:443/' ],
|
||||
[ true, 'https://example.org:443/' ],
|
||||
|
||||
# Part after the hostname is / or / with something else
|
||||
[ true, 'http://example/#' ],
|
||||
[ true, 'http://example/!' ],
|
||||
[ true, 'http://example/:' ],
|
||||
[ true, 'http://example/.' ],
|
||||
[ true, 'http://example/?' ],
|
||||
[ true, 'http://example/+' ],
|
||||
[ true, 'http://example/=' ],
|
||||
[ true, 'http://example/&' ],
|
||||
[ true, 'http://example/%' ],
|
||||
[ true, 'http://example/@' ],
|
||||
[ true, 'http://example/-' ],
|
||||
[ true, 'http://example//' ],
|
||||
[ true, 'http://example/&' ],
|
||||
|
||||
# Fragment
|
||||
[ true, 'http://exam#ple.org', ], # This one is valid, really!
|
||||
[ true, 'http://example.org:80#anchor' ],
|
||||
[ true, 'http://example.org/?id#anchor' ],
|
||||
[ true, 'http://example.org/?#anchor' ],
|
||||
|
||||
[ false, 'http://a ¿non !!sens after', 'Allow anything after URI' ],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in a new issue