From 33471e389f126de413619b53afc4520264ccda3a Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Sun, 17 Jan 2016 21:33:55 +0000 Subject: [PATCH] Pass redirect count using options Removing the risk it might be preserved between requests. --- src/Composer/Util/RemoteFilesystem.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/Composer/Util/RemoteFilesystem.php b/src/Composer/Util/RemoteFilesystem.php index ef2a91e26..1216761ec 100644 --- a/src/Composer/Util/RemoteFilesystem.php +++ b/src/Composer/Util/RemoteFilesystem.php @@ -38,7 +38,7 @@ class RemoteFilesystem private $lastHeaders; private $storeAuth; private $degradedMode = false; - private $redirects = 0; + private $redirects; private $maxRedirects = 20; /** @@ -208,6 +208,7 @@ class RemoteFilesystem $this->lastProgress = null; $this->retryAuthFailure = true; $this->lastHeaders = array(); + $this->redirects = 1; // The first request counts. // capture username/password from URL if there is one if (preg_match('{^https?://(.+):(.+)@([^/]+)}i', $fileUrl, $match)) { @@ -220,6 +221,12 @@ class RemoteFilesystem unset($additionalOptions['retry-auth-failure']); } + if (isset($additionalOptions['redirects'])) { + $this->redirects = $additionalOptions['redirects']; + + unset($additionalOptions['redirects']); + } + $options = $this->getOptionsForUrl($originUrl, $additionalOptions); $userlandFollow = isset($options['http']['follow_location']) && !$options['http']['follow_location']; @@ -351,12 +358,10 @@ class RemoteFilesystem $this->io->writeError(sprintf('Following redirect (%u)', $this->redirects)); } + $additionalOptions['redirects'] = $this->redirects; + // TODO: Not so sure about preserving origin here... - $result = $this->get($this->originUrl, $targetUrl, $additionalOptions, $this->fileName, $this->progress); - - $this->redirects--; - - return $result; + return $this->get($this->originUrl, $targetUrl, $additionalOptions, $this->fileName, $this->progress); } if (!$this->retry) {