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