From bb8387e5a0680769be7a1e4a37f5057dbe135b28 Mon Sep 17 00:00:00 2001 From: John Stevenson Date: Tue, 17 Sep 2024 15:14:47 +0100 Subject: [PATCH] Remove proxy transition fallback (#11938) --- .../how-to-use-composer-behind-a-proxy.md | 12 ------- src/Composer/Console/Application.php | 11 ------ src/Composer/Util/Http/ProxyManager.php | 36 ------------------- .../Test/Util/Http/ProxyManagerTest.php | 26 +------------- .../Test/Util/StreamContextFactoryTest.php | 4 +-- 5 files changed, 3 insertions(+), 86 deletions(-) diff --git a/doc/faqs/how-to-use-composer-behind-a-proxy.md b/doc/faqs/how-to-use-composer-behind-a-proxy.md index 58f82ebcb..ebefaced0 100644 --- a/doc/faqs/how-to-use-composer-behind-a-proxy.md +++ b/doc/faqs/how-to-use-composer-behind-a-proxy.md @@ -104,15 +104,3 @@ Setting the value to `*` will bypass the proxy for all requests. Composer originally provided `HTTP_PROXY_REQUEST_FULLURI` and `HTTPS_PROXY_REQUEST_FULLURI` to help mitigate issues with misbehaving proxies. These are no longer required or used. - -## Requirement changes - -Composer <2.8 used `http_proxy` for both HTTP and HTTPS requests if `https_proxy` was not set, -but as of Composer 2.8.0 it requires [scheme-specific](#usage) environment variables. - -The reason for this change is to align Composer with current practice across other popular tools. To help -with the transition, as of Composer 2.7.3 the original behaviour remains but a warning message is -shown instructing the user to add an `https_proxy` environment variable. - -To prevent the original behaviour during the transition period, set an empty environment variable -(`https_proxy=`). diff --git a/src/Composer/Console/Application.php b/src/Composer/Console/Application.php index 3a784f8a8..7c511f994 100644 --- a/src/Composer/Console/Application.php +++ b/src/Composer/Console/Application.php @@ -43,7 +43,6 @@ use Composer\EventDispatcher\ScriptExecutionException; use Composer\Exception\NoSslException; use Composer\XdebugHandler\XdebugHandler; use Symfony\Component\Process\Exception\ProcessTimedOutException; -use Composer\Util\Http\ProxyManager; /** * The console application that handles the commands @@ -383,8 +382,6 @@ class Application extends BaseApplication } try { - $proxyManager = ProxyManager::getInstance(); - if ($input->hasParameterOption('--profile')) { $startTime = microtime(true); $this->io->enableDebugging($startTime); @@ -406,14 +403,6 @@ class Application extends BaseApplication $io->writeError('Memory usage: '.round(memory_get_usage() / 1024 / 1024, 2).'MiB (peak: '.round(memory_get_peak_usage() / 1024 / 1024, 2).'MiB), time: '.round(microtime(true) - $startTime, 2).'s'); } - if ($proxyManager->needsTransitionWarning()) { - $io->writeError(''); - $io->writeError('Composer now requires separate proxy environment variables for HTTP and HTTPS requests.'); - $io->writeError('Please set `https_proxy` in addition to your existing proxy environment variables.'); - $io->writeError('This fallback (and warning) will be removed in Composer 2.8.0.'); - $io->writeError('https://getcomposer.org/doc/faqs/how-to-use-composer-behind-a-proxy.md'); - } - return $result; } catch (ScriptExecutionException $e) { if ($this->getDisablePluginsByDefault() && $this->isRunningAsRoot() && !$this->io->isInteractive()) { diff --git a/src/Composer/Util/Http/ProxyManager.php b/src/Composer/Util/Http/ProxyManager.php index 0571780fe..247105fa5 100644 --- a/src/Composer/Util/Http/ProxyManager.php +++ b/src/Composer/Util/Http/ProxyManager.php @@ -33,20 +33,8 @@ class ProxyManager /** @var ?self */ private static $instance = null; - /** The following 3 properties can be removed after the transition period */ - - /** @var bool */ - private $ignoreHttpsProxy = false; - /** @var bool */ - private $isTransitional = false; - /** @var bool */ - private $needsTransitionWarning = false; - private function __construct() { - // this can be removed after the transition period - $this->isTransitional = true; - try { $this->getProxyData(); } catch (\RuntimeException $e) { @@ -96,16 +84,6 @@ class ProxyManager return $proxy->toRequestProxy($scheme); } - /** - * Returns true if the user needs to set an https_proxy environment variable - * - * This method can be removed after the transition period - */ - public function needsTransitionWarning(): bool - { - return $this->needsTransitionWarning; - } - /** * Returns a ProxyItem if one is set for the scheme, otherwise null */ @@ -116,15 +94,6 @@ class ProxyManager } if ($scheme === 'https') { - // this can be removed after the transition period - if ($this->isTransitional && $this->httpsProxy === null) { - if ($this->httpProxy !== null && !$this->ignoreHttpsProxy) { - $this->needsTransitionWarning = true; - - return $this->httpProxy; - } - } - return $this->httpsProxy; } @@ -179,11 +148,6 @@ class ProxyManager if ($_SERVER[$name] !== '') { return [$_SERVER[$name], $name]; } - // this can be removed after the transition period - if ($this->isTransitional && strtolower($name) === 'https_proxy') { - $this->ignoreHttpsProxy = true; - break; - } } } diff --git a/tests/Composer/Test/Util/Http/ProxyManagerTest.php b/tests/Composer/Test/Util/Http/ProxyManagerTest.php index 80c88a844..04c756b48 100644 --- a/tests/Composer/Test/Util/Http/ProxyManagerTest.php +++ b/tests/Composer/Test/Util/Http/ProxyManagerTest.php @@ -20,11 +20,6 @@ use Composer\Test\TestCase; */ class ProxyManagerTest extends TestCase { - // isTransitional can be removed after the transition period - - /** @var bool */ - private $isTransitional = true; - protected function setUp(): void { unset( @@ -142,31 +137,12 @@ class ProxyManagerTest extends TestCase public function testNoHttpsProxyDoesNotUseHttpProxy(): void { $_SERVER['http_proxy'] = 'http://proxy.com:80'; - - // This can be removed after the transition period. - // An empty https_proxy value prevents using any http_proxy - if ($this->isTransitional) { - $_SERVER['https_proxy'] = ''; - } - $proxyManager = ProxyManager::getInstance(); + $proxy = $proxyManager->getProxyForRequest('https://repo.org'); self::assertSame('', $proxy->getStatus()); } - /** - * This test can be removed after the transition period - */ - public function testTransitional(): void - { - $_SERVER['http_proxy'] = 'http://proxy.com:80'; - $proxyManager = ProxyManager::getInstance(); - - $proxy = $proxyManager->getProxyForRequest('https://repo.org'); - self::assertSame('http://proxy.com:80', $proxy->getStatus()); - self::assertTrue($proxyManager->needsTransitionWarning()); - } - /** * @dataProvider dataRequest * diff --git a/tests/Composer/Test/Util/StreamContextFactoryTest.php b/tests/Composer/Test/Util/StreamContextFactoryTest.php index d1fe5db31..bb89cefd5 100644 --- a/tests/Composer/Test/Util/StreamContextFactoryTest.php +++ b/tests/Composer/Test/Util/StreamContextFactoryTest.php @@ -133,7 +133,7 @@ class StreamContextFactoryTest extends TestCase public function testHttpProxyWithoutPort(): void { - $_SERVER['http_proxy'] = 'http://username:password@proxyserver.net'; + $_SERVER['https_proxy'] = 'http://username:password@proxyserver.net'; $context = StreamContextFactory::getContext('https://example.org', ['http' => ['method' => 'GET', 'header' => 'User-Agent: foo']]); $options = stream_context_get_options($context); @@ -221,7 +221,7 @@ class StreamContextFactoryTest extends TestCase public function testInitOptionsDoesIncludeProxyAuthHeaders(): void { - $_SERVER['http_proxy'] = 'http://username:password@proxyserver.net:3128/'; + $_SERVER['https_proxy'] = 'http://username:password@proxyserver.net:3128/'; $options = []; $options = StreamContextFactory::initOptions('https://example.org', $options);