1
0
Fork 0

Remove proxy transition fallback (#11938)

pull/12086/head
John Stevenson 2024-09-17 15:14:47 +01:00 committed by GitHub
parent 21bf74d2c7
commit bb8387e5a0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 3 additions and 86 deletions

View File

@ -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 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. 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=`).

View File

@ -43,7 +43,6 @@ use Composer\EventDispatcher\ScriptExecutionException;
use Composer\Exception\NoSslException; use Composer\Exception\NoSslException;
use Composer\XdebugHandler\XdebugHandler; use Composer\XdebugHandler\XdebugHandler;
use Symfony\Component\Process\Exception\ProcessTimedOutException; use Symfony\Component\Process\Exception\ProcessTimedOutException;
use Composer\Util\Http\ProxyManager;
/** /**
* The console application that handles the commands * The console application that handles the commands
@ -383,8 +382,6 @@ class Application extends BaseApplication
} }
try { try {
$proxyManager = ProxyManager::getInstance();
if ($input->hasParameterOption('--profile')) { if ($input->hasParameterOption('--profile')) {
$startTime = microtime(true); $startTime = microtime(true);
$this->io->enableDebugging($startTime); $this->io->enableDebugging($startTime);
@ -406,14 +403,6 @@ class Application extends BaseApplication
$io->writeError('<info>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</info>'); $io->writeError('<info>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</info>');
} }
if ($proxyManager->needsTransitionWarning()) {
$io->writeError('');
$io->writeError('<warning>Composer now requires separate proxy environment variables for HTTP and HTTPS requests.</warning>');
$io->writeError('<warning>Please set `https_proxy` in addition to your existing proxy environment variables.</warning>');
$io->writeError('<warning>This fallback (and warning) will be removed in Composer 2.8.0.</warning>');
$io->writeError('<warning>https://getcomposer.org/doc/faqs/how-to-use-composer-behind-a-proxy.md</warning>');
}
return $result; return $result;
} catch (ScriptExecutionException $e) { } catch (ScriptExecutionException $e) {
if ($this->getDisablePluginsByDefault() && $this->isRunningAsRoot() && !$this->io->isInteractive()) { if ($this->getDisablePluginsByDefault() && $this->isRunningAsRoot() && !$this->io->isInteractive()) {

View File

@ -33,20 +33,8 @@ class ProxyManager
/** @var ?self */ /** @var ?self */
private static $instance = null; 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() private function __construct()
{ {
// this can be removed after the transition period
$this->isTransitional = true;
try { try {
$this->getProxyData(); $this->getProxyData();
} catch (\RuntimeException $e) { } catch (\RuntimeException $e) {
@ -96,16 +84,6 @@ class ProxyManager
return $proxy->toRequestProxy($scheme); 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 * Returns a ProxyItem if one is set for the scheme, otherwise null
*/ */
@ -116,15 +94,6 @@ class ProxyManager
} }
if ($scheme === 'https') { 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; return $this->httpsProxy;
} }
@ -179,11 +148,6 @@ class ProxyManager
if ($_SERVER[$name] !== '') { if ($_SERVER[$name] !== '') {
return [$_SERVER[$name], $name]; return [$_SERVER[$name], $name];
} }
// this can be removed after the transition period
if ($this->isTransitional && strtolower($name) === 'https_proxy') {
$this->ignoreHttpsProxy = true;
break;
}
} }
} }

View File

@ -20,11 +20,6 @@ use Composer\Test\TestCase;
*/ */
class ProxyManagerTest extends TestCase class ProxyManagerTest extends TestCase
{ {
// isTransitional can be removed after the transition period
/** @var bool */
private $isTransitional = true;
protected function setUp(): void protected function setUp(): void
{ {
unset( unset(
@ -142,31 +137,12 @@ class ProxyManagerTest extends TestCase
public function testNoHttpsProxyDoesNotUseHttpProxy(): void public function testNoHttpsProxyDoesNotUseHttpProxy(): void
{ {
$_SERVER['http_proxy'] = 'http://proxy.com:80'; $_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(); $proxyManager = ProxyManager::getInstance();
$proxy = $proxyManager->getProxyForRequest('https://repo.org'); $proxy = $proxyManager->getProxyForRequest('https://repo.org');
self::assertSame('', $proxy->getStatus()); 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 * @dataProvider dataRequest
* *

View File

@ -133,7 +133,7 @@ class StreamContextFactoryTest extends TestCase
public function testHttpProxyWithoutPort(): void 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']]); $context = StreamContextFactory::getContext('https://example.org', ['http' => ['method' => 'GET', 'header' => 'User-Agent: foo']]);
$options = stream_context_get_options($context); $options = stream_context_get_options($context);
@ -221,7 +221,7 @@ class StreamContextFactoryTest extends TestCase
public function testInitOptionsDoesIncludeProxyAuthHeaders(): void public function testInitOptionsDoesIncludeProxyAuthHeaders(): void
{ {
$_SERVER['http_proxy'] = 'http://username:password@proxyserver.net:3128/'; $_SERVER['https_proxy'] = 'http://username:password@proxyserver.net:3128/';
$options = []; $options = [];
$options = StreamContextFactory::initOptions('https://example.org', $options); $options = StreamContextFactory::initOptions('https://example.org', $options);