diff --git a/administrator/components/com_joomlaupdate/models/default.php b/administrator/components/com_joomlaupdate/models/default.php index 00aa344b4774f..1c3b0293e5745 100644 --- a/administrator/components/com_joomlaupdate/models/default.php +++ b/administrator/components/com_joomlaupdate/models/default.php @@ -11,6 +11,8 @@ use Joomla\CMS\Extension\ExtensionHelper; use Joomla\CMS\Filter\InputFilter; +use Joomla\CMS\Http\HttpFactory; +use Joomla\Registry\Registry; jimport('joomla.filesystem.folder'); jimport('joomla.filesystem.file'); @@ -298,13 +300,39 @@ public function download() $updateInfo = $this->getUpdateInformation(); $packageURL = trim($updateInfo['object']->downloadurl->_data); $sources = $updateInfo['object']->get('downloadSources', array()); - $headers = get_headers($packageURL, 1); + + // We have to manually follow the redirects here so we set the option to false. + $httpOptions = new Registry; + $httpOptions->set('follow_location', false); + + try + { + $head = HttpFactory::getHttp($httpOptions)->head($packageURL); + } + catch (RuntimeException $e) + { + // Passing false here -> download failed message + $response['basename'] = false; + + return $response; + } // Follow the Location headers until the actual download URL is known - while (isset($headers['Location'])) + while (isset($head->headers['location'])) { - $packageURL = $headers['Location']; - $headers = get_headers($packageURL, 1); + $packageURL = $head->headers['location']; + + try + { + $head = HttpFactory::getHttp($httpOptions)->head($packageURL); + } + catch (RuntimeException $e) + { + // Passing false here -> download failed message + $response['basename'] = false; + + return $response; + } } // Remove protocol, path and query string from URL