Improve proxy reporting in Diagnose command (#11932)
parent
3cc490d4c4
commit
41fb6146b0
|
@ -44,6 +44,8 @@ use Composer\XdebugHandler\XdebugHandler;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
use Symfony\Component\Process\ExecutableFinder;
|
use Symfony\Component\Process\ExecutableFinder;
|
||||||
|
use Composer\Util\Http\ProxyManager;
|
||||||
|
use Composer\Util\Http\RequestProxy;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||||
|
@ -115,10 +117,21 @@ EOT
|
||||||
$io->write('Checking https connectivity to packagist: ', false);
|
$io->write('Checking https connectivity to packagist: ', false);
|
||||||
$this->outputResult($this->checkHttp('https', $config));
|
$this->outputResult($this->checkHttp('https', $config));
|
||||||
|
|
||||||
$opts = stream_context_get_options(StreamContextFactory::getContext('http://example.org'));
|
$proxyManager = ProxyManager::getInstance();
|
||||||
if (!empty($opts['http']['proxy'])) {
|
$protos = $config->get('disable-tls') === true ? ['http'] : ['http', 'https'];
|
||||||
|
try {
|
||||||
|
foreach ($protos as $proto) {
|
||||||
|
$proxy = $proxyManager->getProxyForRequest($proto.'://repo.packagist.org');
|
||||||
|
if ($proxy->getStatus() !== '') {
|
||||||
|
$type = $proxy->isSecure() ? 'HTTPS' : 'HTTP';
|
||||||
|
$io->write('Checking '.$type.' proxy with '.$proto.': ', false);
|
||||||
|
$this->outputResult($this->checkHttpProxy($proxy, $proto));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (TransportException $e) {
|
||||||
$io->write('Checking HTTP proxy: ', false);
|
$io->write('Checking HTTP proxy: ', false);
|
||||||
$this->outputResult($this->checkHttpProxy());
|
$status = $this->checkConnectivityAndComposerNetworkHttpEnablement();
|
||||||
|
$this->outputResult(is_string($status) ? $status : $e);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count($oauth = $config->get('github-oauth')) > 0) {
|
if (count($oauth = $config->get('github-oauth')) > 0) {
|
||||||
|
@ -298,31 +311,36 @@ EOT
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string|true|\Exception
|
* @return string|\Exception
|
||||||
*/
|
*/
|
||||||
private function checkHttpProxy()
|
private function checkHttpProxy(RequestProxy $proxy, string $protocol)
|
||||||
{
|
{
|
||||||
$result = $this->checkConnectivityAndComposerNetworkHttpEnablement();
|
$result = $this->checkConnectivityAndComposerNetworkHttpEnablement();
|
||||||
if ($result !== true) {
|
if ($result !== true) {
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
$protocol = extension_loaded('openssl') ? 'https' : 'http';
|
|
||||||
try {
|
try {
|
||||||
$json = $this->httpDownloader->get($protocol . '://repo.packagist.org/packages.json')->decodeJson();
|
$proxyStatus = $proxy->getStatus();
|
||||||
|
|
||||||
|
if ($proxy->isExcludedByNoProxy()) {
|
||||||
|
return '<info>SKIP</> <comment>Because repo.packagist.org is '.$proxyStatus.'</>';
|
||||||
|
}
|
||||||
|
|
||||||
|
$json = $this->httpDownloader->get($protocol.'://repo.packagist.org/packages.json')->decodeJson();
|
||||||
$hash = reset($json['provider-includes']);
|
$hash = reset($json['provider-includes']);
|
||||||
$hash = $hash['sha256'];
|
$hash = $hash['sha256'];
|
||||||
$path = str_replace('%hash%', $hash, key($json['provider-includes']));
|
$path = str_replace('%hash%', $hash, key($json['provider-includes']));
|
||||||
$provider = $this->httpDownloader->get($protocol . '://repo.packagist.org/'.$path)->getBody();
|
$provider = $this->httpDownloader->get($protocol.'://repo.packagist.org/'.$path)->getBody();
|
||||||
|
|
||||||
if (hash('sha256', $provider) !== $hash) {
|
if (hash('sha256', $provider) !== $hash) {
|
||||||
return 'It seems that your proxy is modifying http traffic on the fly';
|
return '<warning>It seems that your proxy ('.$proxyStatus.') is modifying '.$protocol.' traffic on the fly</>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return '<info>OK</> <comment>'.$proxyStatus.'</>';
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return $e;
|
return $e;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue