diff --git a/src/Composer/Util/StreamContextFactory.php b/src/Composer/Util/StreamContextFactory.php index 04561670e..0cc591484 100644 --- a/src/Composer/Util/StreamContextFactory.php +++ b/src/Composer/Util/StreamContextFactory.php @@ -42,20 +42,20 @@ final class StreamContextFactory $proxyPort = parse_url($proxy, PHP_URL_PORT); if (isset($proxyPort)) { - $proxyURL .= ":" . $proxyPort; + $proxyURL .= ":" . $proxyPort; } else { - if ('http://' == substr($proxyURL, 0, 7)) { - $proxyURL .= ":80"; - } else if ('https://' == substr($proxyURL, 0, 8)) { - $proxyURL .= ":443"; - } + if ('http://' == substr($proxyURL, 0, 7)) { + $proxyURL .= ":80"; + } else if ('https://' == substr($proxyURL, 0, 8)) { + $proxyURL .= ":443"; + } } // http(s):// is not supported in proxy $proxyURL = str_replace(array('http://', 'https://'), array('tcp://', 'ssl://'), $proxyURL); if (0 === strpos($proxyURL, 'ssl:') && !extension_loaded('openssl')) { - throw new \RuntimeException('You must enable the openssl extension to use a proxy over https'); + throw new \RuntimeException('You must enable the openssl extension to use a proxy over https'); } $options['http'] = array( @@ -68,18 +68,18 @@ final class StreamContextFactory $pass = parse_url($proxy, PHP_URL_PASS); if (isset($user)) { - $auth = $user; - if (isset($pass)) { - $auth .= ":{$pass}"; - } - $auth = base64_encode($auth); - - // Preserve headers if already set in default options - if (isset($defaultOptions['http']) && isset($defaultOptions['http']['header'])) { - $defaultOptions['http']['header'] .= "Proxy-Authorization: Basic {$auth}\r\n"; - } else { - $options['http']['header'] = "Proxy-Authorization: Basic {$auth}\r\n"; - } + $auth = $user; + if (isset($pass)) { + $auth .= ":{$pass}"; + } + $auth = base64_encode($auth); + + // Preserve headers if already set in default options + if (isset($defaultOptions['http']) && isset($defaultOptions['http']['header'])) { + $defaultOptions['http']['header'] .= "Proxy-Authorization: Basic {$auth}\r\n"; + } else { + $options['http']['header'] = "Proxy-Authorization: Basic {$auth}\r\n"; + } } } diff --git a/tests/Composer/Test/Util/StreamContextFactoryTest.php b/tests/Composer/Test/Util/StreamContextFactoryTest.php index d39fbe340..7fa74e0d9 100644 --- a/tests/Composer/Test/Util/StreamContextFactoryTest.php +++ b/tests/Composer/Test/Util/StreamContextFactoryTest.php @@ -96,8 +96,8 @@ class StreamContextFactoryTest extends \PHPUnit_Framework_TestCase if (extension_loaded('openssl')) { $context = StreamContextFactory::getContext(); $options = stream_context_get_options($context); - - $this->assertEquals(array('http' => array( + + $this->assertEquals(array('http' => array( 'proxy' => $expected, 'request_fulluri' => true, )), $options);