Skip to content

Commit

Permalink
Merge pull request #4 from hirak/compat-with-oldcurl
Browse files Browse the repository at this point in the history
compat with nss curl
  • Loading branch information
hirak committed Jan 17, 2016
2 parents e49d453 + 4ade223 commit ea75a59
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
9 changes: 6 additions & 3 deletions src/CurlRemoteFilesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])) {
Expand All @@ -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);

Expand Down
28 changes: 23 additions & 5 deletions src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<curl>
*/
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();
}
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/ParallelDownloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit ea75a59

Please sign in to comment.