Replace deprecated Http::get

Bug: T305813
Change-Id: Ief91d92c556244c36dfcec23f770319bd2f2c537
This commit is contained in:
Umherirrender 2022-12-11 14:18:17 +01:00
parent 0a06382d72
commit 88aa29cb72
2 changed files with 9 additions and 4 deletions

View file

@ -2,8 +2,8 @@
namespace CookieWarning; namespace CookieWarning;
use Http;
use InvalidArgumentException; use InvalidArgumentException;
use MediaWiki\Http\HttpRequestFactory;
use Wikimedia\IPUtils; use Wikimedia\IPUtils;
/** /**
@ -13,14 +13,19 @@ class HttpGeoLocation implements GeoLocation {
private $geoIPServiceURL; private $geoIPServiceURL;
private $locatedIPs = []; private $locatedIPs = [];
/** @var HttpRequestFactory */
private $httpRequestFactory;
/** /**
* @param string $geoIPServiceURL * @param string $geoIPServiceURL
* @param HttpRequestFactory $httpRequestFactory
*/ */
public function __construct( $geoIPServiceURL ) { public function __construct( $geoIPServiceURL, HttpRequestFactory $httpRequestFactory ) {
if ( !is_string( $geoIPServiceURL ) || !$geoIPServiceURL ) { if ( !is_string( $geoIPServiceURL ) || !$geoIPServiceURL ) {
throw new InvalidArgumentException( 'The geoIPServiceUL is invalid' ); throw new InvalidArgumentException( 'The geoIPServiceUL is invalid' );
} }
$this->geoIPServiceURL = $geoIPServiceURL; $this->geoIPServiceURL = $geoIPServiceURL;
$this->httpRequestFactory = $httpRequestFactory;
} }
/** /**
@ -38,7 +43,7 @@ class HttpGeoLocation implements GeoLocation {
if ( substr( $this->geoIPServiceURL, -1 ) !== '/' ) { if ( substr( $this->geoIPServiceURL, -1 ) !== '/' ) {
$this->geoIPServiceURL .= '/'; $this->geoIPServiceURL .= '/';
} }
$json = Http::get( $this->geoIPServiceURL . $ip, [ $json = $this->httpRequestFactory->get( $this->geoIPServiceURL . $ip, [
'timeout' => '2', 'timeout' => '2',
] ); ] );
if ( !$json ) { if ( !$json ) {

View file

@ -18,7 +18,7 @@ return [
if ( !is_string( $geoIPServiceURL ) || !$geoIPServiceURL ) { if ( !is_string( $geoIPServiceURL ) || !$geoIPServiceURL ) {
return new NoopGeoLocation(); return new NoopGeoLocation();
} }
return new HttpGeoLocation( $geoIPServiceURL ); return new HttpGeoLocation( $geoIPServiceURL, $services->getHttpRequestFactory() );
}, },
'CookieWarning.Decisions' => static function ( MediaWikiServices $services ) { 'CookieWarning.Decisions' => static function ( MediaWikiServices $services ) {
return new Decisions( return new Decisions(