1
0
Fork 0

Precious community feedback-based refactoring

pull/649/head
Maxim Chernyshev 2012-05-02 17:21:58 +08:00
parent 1ae0a1b7af
commit 5294cb222c
2 changed files with 23 additions and 24 deletions

View File

@ -34,18 +34,20 @@ final class StreamContextFactory
// Handle system proxy
if (isset($_SERVER['HTTP_PROXY']) || isset($_SERVER['http_proxy'])) {
// Some systems seem to rely on a lowercased version instead...
$proxy = isset($_SERVER['http_proxy']) ? $_SERVER['http_proxy'] : $_SERVER['HTTP_PROXY'];
$proxy = parse_url(isset($_SERVER['http_proxy']) ? $_SERVER['http_proxy'] : $_SERVER['HTTP_PROXY']);
} else {
$proxy = false;
}
$proxyURL = parse_url($proxy, PHP_URL_SCHEME) . "://";
$proxyURL .= parse_url($proxy, PHP_URL_HOST);
if (false !== $proxy) {
$proxyURL = (isset($proxy['scheme']) ? $proxy['scheme'] : '') . '://';
$proxyURL .= isset($proxy['host']) ? $proxy['host'] : '';
$proxyPort = parse_url($proxy, PHP_URL_PORT);
if (isset($proxyPort)) {
$proxyURL .= ":" . $proxyPort;
} else if ('http://' == substr($proxyURL, 0, 7)) {
if (isset($proxy['port'])) {
$proxyURL .= ":" . $proxy['port'];
} elseif ('http://' == substr($proxyURL, 0, 7)) {
$proxyURL .= ":80";
} else if ('https://' == substr($proxyURL, 0, 8)) {
} elseif ('https://' == substr($proxyURL, 0, 8)) {
$proxyURL .= ":443";
}
@ -61,14 +63,10 @@ final class StreamContextFactory
'request_fulluri' => true,
);
// Extract authentication credentials from the proxy url
$user = parse_url($proxy, PHP_URL_USER);
$pass = parse_url($proxy, PHP_URL_PASS);
if (isset($user)) {
$auth = $user;
if (isset($pass)) {
$auth .= ":{$pass}";
if (isset($proxy['user'])) {
$auth = $proxy['user'];
if (isset($proxy['pass'])) {
$auth .= ':' . $proxy['pass'];
}
$auth = base64_encode($auth);
@ -80,6 +78,7 @@ final class StreamContextFactory
}
}
}
$options = array_merge_recursive($options, $defaultOptions);
return stream_context_create($options, $defaultParams);