diff --git a/src/Composer/Exception/NoSslException.php b/src/Composer/Exception/NoSslException.php index 017cac382..55c81fea9 100644 --- a/src/Composer/Exception/NoSslException.php +++ b/src/Composer/Exception/NoSslException.php @@ -13,6 +13,8 @@ namespace Composer\Exception; /** + * Specific exception for Composer\Util\HttpDownloader creation. + * * @author Jordi Boggiano */ class NoSslException extends \RuntimeException diff --git a/src/Composer/Util/StreamContextFactory.php b/src/Composer/Util/StreamContextFactory.php index 781fda6ae..65ca3dd3e 100644 --- a/src/Composer/Util/StreamContextFactory.php +++ b/src/Composer/Util/StreamContextFactory.php @@ -75,27 +75,27 @@ final class StreamContextFactory // Add stream proxy options if there is a proxy if (!$forCurl) { $proxy = ProxyManager::getInstance()->getProxyForRequest($url); - $isHttpsRequest = 0 === strpos($url, 'https://'); + if ($proxyOptions = $proxy->getContextOptions()) { + $isHttpsRequest = 0 === strpos($url, 'https://'); - if ($proxy->isSecure()) { - if (!extension_loaded('openssl')) { - throw new TransportException('You must enable the openssl extension to use a secure proxy.'); + if ($proxy->isSecure()) { + if (!extension_loaded('openssl')) { + throw new TransportException('You must enable the openssl extension to use a secure proxy.'); + } + if ($isHttpsRequest) { + throw new TransportException('You must enable the curl extension to make https requests through a secure proxy.'); + } + } elseif ($isHttpsRequest && !extension_loaded('openssl')) { + throw new TransportException('You must enable the openssl extension to make https requests through a proxy.'); } - if ($isHttpsRequest) { - throw new TransportException('You must enable the curl extension to make https requests through a secure proxy.'); + + // Header will be a Proxy-Authorization string or not set + if (isset($proxyOptions['http']['header'])) { + $options['http']['header'][] = $proxyOptions['http']['header']; + unset($proxyOptions['http']['header']); } - } elseif ($isHttpsRequest && !extension_loaded('openssl')) { - throw new TransportException('You must enable the openssl extension to make https requests through a proxy.'); + $options = array_replace_recursive($options, $proxyOptions); } - - $proxyOptions = $proxy->getContextOptions(); - - // Header will be a Proxy-Authorization string or not set - if (isset($proxyOptions['http']['header'])) { - $options['http']['header'][] = $proxyOptions['http']['header']; - unset($proxyOptions['http']['header']); - } - $options = array_replace_recursive($options, $proxyOptions); } if (defined('HHVM_VERSION')) {