From ed5f7a6d2719c857822a64639094d1d712f4f8e5 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Thu, 21 Feb 2019 23:44:56 +0000 Subject: [PATCH] ForeignResourceManager: Catch responses other than 200 OK Makes it easier to catch issues like at I839301d05877eb63279c. Change-Id: I22b9af7bf36a256d8363ed96fe42c087e0c8a895 --- includes/ForeignResourceManager.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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 ) { -- 2.20.1