Fixed indentation
parent
8918551f29
commit
37476eb61f
|
@ -42,20 +42,20 @@ final class StreamContextFactory
|
||||||
$proxyPort = parse_url($proxy, PHP_URL_PORT);
|
$proxyPort = parse_url($proxy, PHP_URL_PORT);
|
||||||
|
|
||||||
if (isset($proxyPort)) {
|
if (isset($proxyPort)) {
|
||||||
$proxyURL .= ":" . $proxyPort;
|
$proxyURL .= ":" . $proxyPort;
|
||||||
} else {
|
} else {
|
||||||
if ('http://' == substr($proxyURL, 0, 7)) {
|
if ('http://' == substr($proxyURL, 0, 7)) {
|
||||||
$proxyURL .= ":80";
|
$proxyURL .= ":80";
|
||||||
} else if ('https://' == substr($proxyURL, 0, 8)) {
|
} else if ('https://' == substr($proxyURL, 0, 8)) {
|
||||||
$proxyURL .= ":443";
|
$proxyURL .= ":443";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// http(s):// is not supported in proxy
|
// http(s):// is not supported in proxy
|
||||||
$proxyURL = str_replace(array('http://', 'https://'), array('tcp://', 'ssl://'), $proxyURL);
|
$proxyURL = str_replace(array('http://', 'https://'), array('tcp://', 'ssl://'), $proxyURL);
|
||||||
|
|
||||||
if (0 === strpos($proxyURL, 'ssl:') && !extension_loaded('openssl')) {
|
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(
|
$options['http'] = array(
|
||||||
|
@ -68,18 +68,18 @@ final class StreamContextFactory
|
||||||
$pass = parse_url($proxy, PHP_URL_PASS);
|
$pass = parse_url($proxy, PHP_URL_PASS);
|
||||||
|
|
||||||
if (isset($user)) {
|
if (isset($user)) {
|
||||||
$auth = $user;
|
$auth = $user;
|
||||||
if (isset($pass)) {
|
if (isset($pass)) {
|
||||||
$auth .= ":{$pass}";
|
$auth .= ":{$pass}";
|
||||||
}
|
}
|
||||||
$auth = base64_encode($auth);
|
$auth = base64_encode($auth);
|
||||||
|
|
||||||
// Preserve headers if already set in default options
|
// Preserve headers if already set in default options
|
||||||
if (isset($defaultOptions['http']) && isset($defaultOptions['http']['header'])) {
|
if (isset($defaultOptions['http']) && isset($defaultOptions['http']['header'])) {
|
||||||
$defaultOptions['http']['header'] .= "Proxy-Authorization: Basic {$auth}\r\n";
|
$defaultOptions['http']['header'] .= "Proxy-Authorization: Basic {$auth}\r\n";
|
||||||
} else {
|
} else {
|
||||||
$options['http']['header'] = "Proxy-Authorization: Basic {$auth}\r\n";
|
$options['http']['header'] = "Proxy-Authorization: Basic {$auth}\r\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -97,7 +97,7 @@ class StreamContextFactoryTest extends \PHPUnit_Framework_TestCase
|
||||||
$context = StreamContextFactory::getContext();
|
$context = StreamContextFactory::getContext();
|
||||||
$options = stream_context_get_options($context);
|
$options = stream_context_get_options($context);
|
||||||
|
|
||||||
$this->assertEquals(array('http' => array(
|
$this->assertEquals(array('http' => array(
|
||||||
'proxy' => $expected,
|
'proxy' => $expected,
|
||||||
'request_fulluri' => true,
|
'request_fulluri' => true,
|
||||||
)), $options);
|
)), $options);
|
||||||
|
|
Loading…
Reference in New Issue