Remove ability to override the entire HttpDownloader instance in PRE_FILE_DOWNLOAD events
parent
549ccd8f79
commit
bb2f64c7bc
|
@ -106,21 +106,19 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
|
|||
|
||||
$io = $this->io;
|
||||
$cache = $this->cache;
|
||||
$originalHttpDownloader = $this->httpDownloader;
|
||||
$httpDownloader = $this->httpDownloader;
|
||||
$eventDispatcher = $this->eventDispatcher;
|
||||
$filesystem = $this->filesystem;
|
||||
$self = $this;
|
||||
|
||||
$accept = null;
|
||||
$reject = null;
|
||||
$download = function () use ($io, $output, $originalHttpDownloader, $cache, $eventDispatcher, $package, $fileName, $path, &$urls, &$accept, &$reject) {
|
||||
$download = function () use ($io, $output, $httpDownloader, $cache, $eventDispatcher, $package, $fileName, $path, &$urls, &$accept, &$reject) {
|
||||
$url = reset($urls);
|
||||
|
||||
$httpDownloader = $originalHttpDownloader;
|
||||
if ($eventDispatcher) {
|
||||
$preFileDownloadEvent = new PreFileDownloadEvent(PluginEvents::PRE_FILE_DOWNLOAD, $httpDownloader, $url['processed']);
|
||||
$eventDispatcher->dispatch($preFileDownloadEvent->getName(), $preFileDownloadEvent);
|
||||
$httpDownloader = $preFileDownloadEvent->getHttpDownloader();
|
||||
}
|
||||
|
||||
$checksum = $package->getDistSha1Checksum();
|
||||
|
|
|
@ -25,7 +25,7 @@ class PreFileDownloadEvent extends Event
|
|||
/**
|
||||
* @var HttpDownloader
|
||||
*/
|
||||
private $rfs;
|
||||
private $httpDownloader;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
|
@ -36,13 +36,13 @@ class PreFileDownloadEvent extends Event
|
|||
* Constructor.
|
||||
*
|
||||
* @param string $name The event name
|
||||
* @param HttpDownloader $rfs
|
||||
* @param HttpDownloader $httpDownloader
|
||||
* @param string $processedUrl
|
||||
*/
|
||||
public function __construct($name, HttpDownloader $rfs, $processedUrl)
|
||||
public function __construct($name, HttpDownloader $httpDownloader, $processedUrl)
|
||||
{
|
||||
parent::__construct($name);
|
||||
$this->rfs = $rfs;
|
||||
$this->httpDownloader = $httpDownloader;
|
||||
$this->processedUrl = $processedUrl;
|
||||
}
|
||||
|
||||
|
@ -51,15 +51,7 @@ class PreFileDownloadEvent extends Event
|
|||
*/
|
||||
public function getHttpDownloader()
|
||||
{
|
||||
return $this->rfs;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param HttpDownloader $rfs
|
||||
*/
|
||||
public function setHttpDownloader(HttpDownloader $rfs)
|
||||
{
|
||||
$this->rfs = $rfs;
|
||||
return $this->httpDownloader;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -898,15 +898,12 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
|
|||
$retries = 3;
|
||||
while ($retries--) {
|
||||
try {
|
||||
$httpDownloader = $this->httpDownloader;
|
||||
|
||||
if ($this->eventDispatcher) {
|
||||
$preFileDownloadEvent = new PreFileDownloadEvent(PluginEvents::PRE_FILE_DOWNLOAD, $this->httpDownloader, $filename);
|
||||
$this->eventDispatcher->dispatch($preFileDownloadEvent->getName(), $preFileDownloadEvent);
|
||||
$httpDownloader = $preFileDownloadEvent->getHttpDownloader();
|
||||
}
|
||||
|
||||
$response = $httpDownloader->get($filename, $this->options);
|
||||
$response = $this->httpDownloader->get($filename, $this->options);
|
||||
$json = $response->getBody();
|
||||
if ($sha256 && $sha256 !== hash('sha256', $json)) {
|
||||
// undo downgrade before trying again if http seems to be hijacked or modifying content somehow
|
||||
|
@ -989,12 +986,9 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
|
|||
$retries = 3;
|
||||
while ($retries--) {
|
||||
try {
|
||||
$httpDownloader = $this->httpDownloader;
|
||||
|
||||
if ($this->eventDispatcher) {
|
||||
$preFileDownloadEvent = new PreFileDownloadEvent(PluginEvents::PRE_FILE_DOWNLOAD, $this->httpDownloader, $filename);
|
||||
$this->eventDispatcher->dispatch($preFileDownloadEvent->getName(), $preFileDownloadEvent);
|
||||
$httpDownloader = $preFileDownloadEvent->getHttpDownloader();
|
||||
}
|
||||
|
||||
$options = $this->options;
|
||||
|
@ -1002,7 +996,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
|
|||
$options['http']['header'] = (array) $options['http']['header'];
|
||||
}
|
||||
$options['http']['header'][] = array('If-Modified-Since: '.$lastModifiedTime);
|
||||
$response = $httpDownloader->get($filename, $options);
|
||||
$response = $this->httpDownloader->get($filename, $options);
|
||||
$json = $response->getBody();
|
||||
if ($json === '' && $response->getStatusCode() === 304) {
|
||||
return true;
|
||||
|
@ -1053,12 +1047,11 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
|
|||
private function asyncFetchFile($filename, $cacheKey, $lastModifiedTime = null)
|
||||
{
|
||||
$retries = 3;
|
||||
$httpDownloader = $this->httpDownloader;
|
||||
|
||||
$httpDownloader = $this->httpDownloader;
|
||||
if ($this->eventDispatcher) {
|
||||
$preFileDownloadEvent = new PreFileDownloadEvent(PluginEvents::PRE_FILE_DOWNLOAD, $this->httpDownloader, $filename);
|
||||
$this->eventDispatcher->dispatch($preFileDownloadEvent->getName(), $preFileDownloadEvent);
|
||||
$httpDownloader = $preFileDownloadEvent->getHttpDownloader();
|
||||
}
|
||||
|
||||
$options = $lastModifiedTime ? array('http' => array('header' => array('If-Modified-Since: '.$lastModifiedTime))) : array();
|
||||
|
|
Loading…
Reference in New Issue