diff --git a/src/Composer/Util/NoProxyPattern.php b/src/Composer/Util/NoProxyPattern.php index a5e74d802..930d12e22 100644 --- a/src/Composer/Util/NoProxyPattern.php +++ b/src/Composer/Util/NoProxyPattern.php @@ -135,10 +135,6 @@ class NoProxyPattern // If the ip is within the range, including highest/lowest values, // then it's witin the CIDR range - if ($check >= $low && $check <= $high) { - return true; - } else { - return false; - } + return $check >= $low && $check <= $high; } } diff --git a/src/Composer/Util/StreamContextFactory.php b/src/Composer/Util/StreamContextFactory.php index 1556f03fc..f9d2deb78 100644 --- a/src/Composer/Util/StreamContextFactory.php +++ b/src/Composer/Util/StreamContextFactory.php @@ -63,51 +63,49 @@ final class StreamContextFactory } $options['http']['proxy'] = $proxyURL; - + // Handle no_proxy directive - if (!empty($_SERVER['no_proxy'])) { - $host = parse_url($url, PHP_URL_HOST); - - if (!empty($host)) { - $pattern = new NoProxyPattern($_SERVER['no_proxy']); - - if ($pattern->test($url)) { - $options['http']['proxy'] = ''; - } + if (!empty($_SERVER['no_proxy']) && parse_url($url, PHP_URL_HOST)) { + $pattern = new NoProxyPattern($_SERVER['no_proxy']); + if ($pattern->test($url)) { + unset($options['http']['proxy']); } } - // enabled request_fulluri unless it is explicitly disabled - switch (parse_url($url, PHP_URL_SCHEME)) { - case 'http': // default request_fulluri to true - $reqFullUriEnv = getenv('HTTP_PROXY_REQUEST_FULLURI'); - if ($reqFullUriEnv === false || $reqFullUriEnv === '' || (strtolower($reqFullUriEnv) !== 'false' && (bool) $reqFullUriEnv)) { - $options['http']['request_fulluri'] = true; - } - break; - case 'https': // default request_fulluri to true - $reqFullUriEnv = getenv('HTTPS_PROXY_REQUEST_FULLURI'); - if ($reqFullUriEnv === false || $reqFullUriEnv === '' || (strtolower($reqFullUriEnv) !== 'false' && (bool) $reqFullUriEnv)) { - $options['http']['request_fulluri'] = true; - } - break; - } - - if (isset($proxy['user'])) { - $auth = $proxy['user']; - if (isset($proxy['pass'])) { - $auth .= ':' . $proxy['pass']; + // add request_fulluri and authentication if we still have a proxy to connect to + if (isset($options['http']['proxy'])) { + // enabled request_fulluri unless it is explicitly disabled + switch (parse_url($url, PHP_URL_SCHEME)) { + case 'http': // default request_fulluri to true + $reqFullUriEnv = getenv('HTTP_PROXY_REQUEST_FULLURI'); + if ($reqFullUriEnv === false || $reqFullUriEnv === '' || (strtolower($reqFullUriEnv) !== 'false' && (bool) $reqFullUriEnv)) { + $options['http']['request_fulluri'] = true; + } + break; + case 'https': // default request_fulluri to true + $reqFullUriEnv = getenv('HTTPS_PROXY_REQUEST_FULLURI'); + if ($reqFullUriEnv === false || $reqFullUriEnv === '' || (strtolower($reqFullUriEnv) !== 'false' && (bool) $reqFullUriEnv)) { + $options['http']['request_fulluri'] = true; + } + break; } - $auth = base64_encode($auth); - // Preserve headers if already set in default options - if (isset($defaultOptions['http']['header'])) { - if (is_string($defaultOptions['http']['header'])) { - $defaultOptions['http']['header'] = array($defaultOptions['http']['header']); + if (isset($proxy['user'])) { + $auth = $proxy['user']; + if (isset($proxy['pass'])) { + $auth .= ':' . $proxy['pass']; + } + $auth = base64_encode($auth); + + // Preserve headers if already set in default options + if (isset($defaultOptions['http']['header'])) { + if (is_string($defaultOptions['http']['header'])) { + $defaultOptions['http']['header'] = array($defaultOptions['http']['header']); + } + $defaultOptions['http']['header'][] = "Proxy-Authorization: Basic {$auth}"; + } else { + $options['http']['header'] = array("Proxy-Authorization: Basic {$auth}"); } - $defaultOptions['http']['header'][] = "Proxy-Authorization: Basic {$auth}"; - } else { - $options['http']['header'] = array("Proxy-Authorization: Basic {$auth}"); } } }