Ver Fonte

Pass redirect count using options

Removing the risk it might be preserved between requests.
Chris Smith há 9 anos atrás
pai
commit
33471e389f
1 ficheiros alterados com 11 adições e 6 exclusões
  1. 11 6
      src/Composer/Util/RemoteFilesystem.php

+ 11 - 6
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));
                 }
 
-                // TODO: Not so sure about preserving origin here...
-                $result = $this->get($this->originUrl, $targetUrl, $additionalOptions, $this->fileName, $this->progress);
-
-                $this->redirects--;
+                $additionalOptions['redirects'] = $this->redirects;
 
-                return $result;
+                // TODO: Not so sure about preserving origin here...
+                return $this->get($this->originUrl, $targetUrl, $additionalOptions, $this->fileName, $this->progress);
             }
 
             if (!$this->retry) {