1
0
Fork 0

Use httpdownloader/curl to process install notifications

pull/9374/head
Jordi Boggiano 2020-10-27 13:49:33 +01:00
parent d699e6b36c
commit 881ec8c751
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
2 changed files with 43 additions and 48 deletions

View File

@ -550,64 +550,58 @@ class InstallationManager
public function notifyInstalls(IOInterface $io) public function notifyInstalls(IOInterface $io)
{ {
foreach ($this->notifiablePackages as $repoUrl => $packages) { $promises = array();
$repositoryName = parse_url($repoUrl, PHP_URL_HOST);
if ($io->hasAuthentication($repositoryName)) {
$auth = $io->getAuthentication($repositoryName);
$authStr = base64_encode($auth['username'] . ':' . $auth['password']);
$authHeader = 'Authorization: Basic '.$authStr;
}
// non-batch API, deprecated try {
if (strpos($repoUrl, '%package%')) { foreach ($this->notifiablePackages as $repoUrl => $packages) {
foreach ($packages as $package) { // non-batch API, deprecated
$url = str_replace('%package%', $package->getPrettyName(), $repoUrl); if (strpos($repoUrl, '%package%')) {
foreach ($packages as $package) {
$url = str_replace('%package%', $package->getPrettyName(), $repoUrl);
$params = array( $params = array(
'version' => $package->getPrettyVersion(), 'version' => $package->getPrettyVersion(),
'version_normalized' => $package->getVersion(), 'version_normalized' => $package->getVersion(),
); );
$opts = array('http' => $opts = array(
array( 'retry-auth-failure' => false,
'method' => 'POST', 'http' => array(
'header' => array('Content-type: application/x-www-form-urlencoded'), 'method' => 'POST',
'content' => http_build_query($params, '', '&'), 'header' => array('Content-type: application/x-www-form-urlencoded'),
'timeout' => 3, 'content' => http_build_query($params, '', '&'),
), 'timeout' => 3,
); ),
if (isset($authHeader)) { );
$opts['http']['header'][] = $authHeader;
$promises[] = $this->loop->getHttpDownloader()->add($url, $opts);
} }
$context = StreamContextFactory::getContext($url, $opts); continue;
@file_get_contents($url, false, $context);
} }
continue; $postData = array('downloads' => array());
} foreach ($packages as $package) {
$postData['downloads'][] = array(
'name' => $package->getPrettyName(),
'version' => $package->getVersion(),
);
}
$postData = array('downloads' => array()); $opts = array(
foreach ($packages as $package) { 'retry-auth-failure' => false,
$postData['downloads'][] = array( 'http' => array(
'name' => $package->getPrettyName(), 'method' => 'POST',
'version' => $package->getVersion(), 'header' => array('Content-Type: application/json'),
'content' => json_encode($postData),
'timeout' => 6,
),
); );
$promises[] = $this->loop->getHttpDownloader()->add($repoUrl, $opts);
} }
$opts = array('http' => $this->loop->wait($promises);
array( } catch (\Exception $e) {
'method' => 'POST',
'header' => array('Content-Type: application/json'),
'content' => json_encode($postData),
'timeout' => 6,
),
);
if (isset($authHeader)) {
$opts['http']['header'][] = $authHeader;
}
$context = StreamContextFactory::getContext($repoUrl, $opts);
@file_get_contents($repoUrl, false, $context);
} }
$this->reset(); $this->reset();

View File

@ -56,6 +56,7 @@ class CurlDownloader
'method' => CURLOPT_CUSTOMREQUEST, 'method' => CURLOPT_CUSTOMREQUEST,
'content' => CURLOPT_POSTFIELDS, 'content' => CURLOPT_POSTFIELDS,
'header' => CURLOPT_HTTPHEADER, 'header' => CURLOPT_HTTPHEADER,
'timeout' => CURLOPT_TIMEOUT,
), ),
'ssl' => array( 'ssl' => array(
'cafile' => CURLOPT_CAINFO, 'cafile' => CURLOPT_CAINFO,