diff --git a/src/Composer/Plugin/PreFileDownloadEvent.php b/src/Composer/Plugin/PreFileDownloadEvent.php index 4372bedd6..e4921621e 100644 --- a/src/Composer/Plugin/PreFileDownloadEvent.php +++ b/src/Composer/Plugin/PreFileDownloadEvent.php @@ -47,6 +47,11 @@ class PreFileDownloadEvent extends Event */ private $context; + /** + * @var array + */ + private $transportOptions = array(); + /** * Constructor. * @@ -135,4 +140,28 @@ class PreFileDownloadEvent extends Event { return $this->context; } + + /** + * Returns transport options for the download. + * + * Only available for events with type metadata, for packages set the transport options on the package itself. + * + * @return array + */ + public function getTransportOptions() + { + return $this->transportOptions; + } + + /** + * Sets transport options for the download. + * + * Only available for events with type metadata, for packages set the transport options on the package itself. + * + * @param array $options + */ + public function setTransportOptions(array $options) + { + $this->transportOptions = $options; + } } diff --git a/src/Composer/Repository/ComposerRepository.php b/src/Composer/Repository/ComposerRepository.php index 5225f4709..3d510c570 100644 --- a/src/Composer/Repository/ComposerRepository.php +++ b/src/Composer/Repository/ComposerRepository.php @@ -1088,13 +1088,16 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito $retries = 3; while ($retries--) { try { + $options = $this->options; if ($this->eventDispatcher) { $preFileDownloadEvent = new PreFileDownloadEvent(PluginEvents::PRE_FILE_DOWNLOAD, $this->httpDownloader, $filename, 'metadata', array('repository' => $this)); + $preFileDownloadEvent->setTransportOptions($this->options); $this->eventDispatcher->dispatch($preFileDownloadEvent->getName(), $preFileDownloadEvent); $filename = $preFileDownloadEvent->getProcessedUrl(); + $options = $preFileDownloadEvent->getTransportOptions(); } - $response = $this->httpDownloader->get($filename, $this->options); + $response = $this->httpDownloader->get($filename, $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 @@ -1180,13 +1183,15 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito $retries = 3; while ($retries--) { try { + $options = $this->options; if ($this->eventDispatcher) { $preFileDownloadEvent = new PreFileDownloadEvent(PluginEvents::PRE_FILE_DOWNLOAD, $this->httpDownloader, $filename, 'metadata', array('repository' => $this)); + $preFileDownloadEvent->setTransportOptions($this->options); $this->eventDispatcher->dispatch($preFileDownloadEvent->getName(), $preFileDownloadEvent); $filename = $preFileDownloadEvent->getProcessedUrl(); + $options = $preFileDownloadEvent->getTransportOptions(); } - $options = $this->options; if (isset($options['http']['header'])) { $options['http']['header'] = (array) $options['http']['header']; } @@ -1254,13 +1259,15 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito } $httpDownloader = $this->httpDownloader; + $options = $this->options; if ($this->eventDispatcher) { $preFileDownloadEvent = new PreFileDownloadEvent(PluginEvents::PRE_FILE_DOWNLOAD, $this->httpDownloader, $filename, 'metadata', array('repository' => $this)); + $preFileDownloadEvent->setTransportOptions($this->options); $this->eventDispatcher->dispatch($preFileDownloadEvent->getName(), $preFileDownloadEvent); $filename = $preFileDownloadEvent->getProcessedUrl(); + $options = $preFileDownloadEvent->getTransportOptions(); } - $options = $this->options; if ($lastModifiedTime) { if (isset($options['http']['header'])) { $options['http']['header'] = (array) $options['http']['header'];