From: Timo Tijhof Date: Thu, 21 Feb 2019 23:44:56 +0000 (+0000) Subject: ForeignResourceManager: Catch responses other than 200 OK X-Git-Tag: 1.34.0-rc.0~2747^2 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/exercices/modifier.php?a=commitdiff_plain;h=ed5f7a6d2719c857822a64639094d1d712f4f8e5;p=lhc%2Fweb%2Fwiklou.git ForeignResourceManager: Catch responses other than 200 OK Makes it easier to catch issues like at I839301d05877eb63279c. Change-Id: I22b9af7bf36a256d8363ed96fe42c087e0c8a895 --- diff --git a/includes/ForeignResourceManager.php b/includes/ForeignResourceManager.php index d6175f6dba..18014fa528 100644 --- a/includes/ForeignResourceManager.php +++ b/includes/ForeignResourceManager.php @@ -132,10 +132,14 @@ class ForeignResourceManager { } private function fetch( $src, $integrity ) { - $data = Http::get( $src, [ 'followRedirects' => false ] ); - if ( $data === false ) { + $req = MWHttpRequest::factory( $src, [ 'method' => 'GET', 'followRedirects' => false ] ); + if ( !$req->execute()->isOK() ) { throw new Exception( "Failed to download resource at {$src}" ); } + if ( $req->getStatus() !== 200 ) { + throw new Exception( "Unexpected HTTP {$req->getStatus()} response from {$src}" ); + } + $data = $req->getContent(); $algo = $integrity === null ? $this->defaultAlgo : explode( '-', $integrity )[0]; $actualIntegrity = $algo . '-' . base64_encode( hash( $algo, $data, true ) ); if ( $integrity === $actualIntegrity ) {