Skip to content

Commit

Permalink
Remove proxy transition fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
johnstevenson committed May 7, 2024
1 parent 2fe3244 commit 83c9c67
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 86 deletions.
12 changes: 0 additions & 12 deletions doc/faqs/how-to-use-composer-behind-a-proxy.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=`).
11 changes: 0 additions & 11 deletions src/Composer/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
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
Expand Down Expand Up @@ -384,8 +383,6 @@ function_exists('php_uname') ? php_uname('s') . ' / ' . php_uname('r') : 'Unknow
}

try {
$proxyManager = ProxyManager::getInstance();

if ($input->hasParameterOption('--profile')) {
$startTime = microtime(true);
$this->io->enableDebugging($startTime);
Expand All @@ -407,14 +404,6 @@ function_exists('php_uname') ? php_uname('s') . ' / ' . php_uname('r') : 'Unknow
$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');
}

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;
} catch (ScriptExecutionException $e) {
if ($this->getDisablePluginsByDefault() && $this->isRunningAsRoot() && !$this->io->isInteractive()) {
Expand Down
36 changes: 0 additions & 36 deletions src/Composer/Util/Http/ProxyManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -96,16 +84,6 @@ public function getProxyForRequest(string $requestUrl): RequestProxy
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
*/
Expand All @@ -116,15 +94,6 @@ private function getProxyForScheme(string $scheme): ?ProxyItem
}

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;
}

Expand Down Expand Up @@ -179,11 +148,6 @@ private function getProxyEnv(string $envName): array
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;
}
}
}

Expand Down
26 changes: 1 addition & 25 deletions tests/Composer/Test/Util/Http/ProxyManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@
*/
class ProxyManagerTest extends TestCase
{
// isTransitional can be removed after the transition period

/** @var bool */
private $isTransitional = true;

protected function setUp(): void
{
unset(
Expand Down Expand Up @@ -140,31 +135,12 @@ public function testNoHttpProxyDoesNotUseHttpsProxy(): void
}

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());
self::assertSame('', $proxy->getStatus());
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/Composer/Test/Util/StreamContextFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public function testOptionsArePreserved(): 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']]);
$options = stream_context_get_options($context);
Expand Down Expand Up @@ -221,7 +221,7 @@ public function testEnsureThatfixHttpHeaderFieldMovesContentTypeToEndOfOptions()

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);
Expand Down

0 comments on commit 83c9c67

Please sign in to comment.