diff --git a/src/CurlRemoteFilesystem.php b/src/CurlRemoteFilesystem.php index 0233342..fc0ff4f 100644 --- a/src/CurlRemoteFilesystem.php +++ b/src/CurlRemoteFilesystem.php @@ -113,8 +113,6 @@ protected function fetch($origin, $fileUrl, $progress, $options, $exec) $this->onPreDownload->attach(new Aspects\AspectDegradedMode); } - $ch = Factory::getConnection($origin); - $options += $this->options; // override if ('github' === $request->special && isset($options['github-token'])) { @@ -140,7 +138,12 @@ protected function fetch($origin, $fileUrl, $progress, $options, $exec) $this->onPreDownload->notify(); $opts = $request->getCurlOpts(); - curl_setopt_array($ch, $request->getCurlOpts()); + if (empty($opts[CURLOPT_USERPWD])) { + unset($opts[CURLOPT_USERPWD]); + } + $ch = Factory::getConnection($origin, isset($opts[CURLOPT_USERPWD])); + + curl_setopt_array($ch, $opts); list($execStatus, $response) = $exec($ch, $request); diff --git a/src/Factory.php b/src/Factory.php index 675c969..b556142 100644 --- a/src/Factory.php +++ b/src/Factory.php @@ -25,25 +25,43 @@ private function __construct() } /** + * don't need Authorization * @var array { * 'origin.example.com' => x * } */ private $connections = array(); + /** + * need Authorization header + * @var array { + * 'origin.example.com' => x + * } + */ + private $authConnections = array(); + /** * get cached curl handler * @param string $origin + * @param bool $auth * @return resource */ - public static function getConnection($origin) + public static function getConnection($origin, $auth=false) { $instance = self::getInstance(); - if (isset($instance->connections[$origin])) { - return $instance->connections[$origin]; - } + if ($auth) { + if (isset($instance->authConnections[$origin])) { + return $instance->authConnections[$origin]; + } - return $instance->connections[$origin] = curl_init(); + return $instance->authConnections[$origin] = curl_init(); + } else { + if (isset($instance->connections[$origin])) { + return $instance->connections[$origin]; + } + + return $instance->connections[$origin] = curl_init(); + } } /** diff --git a/src/ParallelDownloader.php b/src/ParallelDownloader.php index 71eb554..01b4883 100644 --- a/src/ParallelDownloader.php +++ b/src/ParallelDownloader.php @@ -103,6 +103,7 @@ public function download(array $packages, array $pluginConfig) $opts = $request->getCurlOpts(); unset($opts[CURLOPT_ENCODING]); + unset($opts[CURLOPT_USERPWD]); curl_setopt_array($ch, $opts); curl_setopt($ch, CURLOPT_FILE, $fp); curl_multi_add_handle($mh, $ch);