1
0
Fork 0

Reformat some code and avoid adding proxy auth if no_proxy matched the url, refs #2017

pull/2175/head
Jordi Boggiano 2013-08-12 00:47:38 +02:00
parent 2492dea4a8
commit 13c7be2d7e
2 changed files with 37 additions and 43 deletions

View File

@ -135,10 +135,6 @@ class NoProxyPattern
// If the ip is within the range, including highest/lowest values, // If the ip is within the range, including highest/lowest values,
// then it's witin the CIDR range // then it's witin the CIDR range
if ($check >= $low && $check <= $high) { return $check >= $low && $check <= $high;
return true;
} else {
return false;
}
} }
} }

View File

@ -65,18 +65,15 @@ final class StreamContextFactory
$options['http']['proxy'] = $proxyURL; $options['http']['proxy'] = $proxyURL;
// Handle no_proxy directive // Handle no_proxy directive
if (!empty($_SERVER['no_proxy'])) { if (!empty($_SERVER['no_proxy']) && parse_url($url, PHP_URL_HOST)) {
$host = parse_url($url, PHP_URL_HOST);
if (!empty($host)) {
$pattern = new NoProxyPattern($_SERVER['no_proxy']); $pattern = new NoProxyPattern($_SERVER['no_proxy']);
if ($pattern->test($url)) { if ($pattern->test($url)) {
$options['http']['proxy'] = ''; unset($options['http']['proxy']);
}
} }
} }
// 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 // enabled request_fulluri unless it is explicitly disabled
switch (parse_url($url, PHP_URL_SCHEME)) { switch (parse_url($url, PHP_URL_SCHEME)) {
case 'http': // default request_fulluri to true case 'http': // default request_fulluri to true
@ -111,6 +108,7 @@ final class StreamContextFactory
} }
} }
} }
}
$options = array_replace_recursive($options, $defaultOptions); $options = array_replace_recursive($options, $defaultOptions);