Simplified proxy port determination and passed tests
parent
2ca50a1ef3
commit
8918551f29
|
@ -43,17 +43,19 @@ final class StreamContextFactory
|
||||||
|
|
||||||
if (isset($proxyPort)) {
|
if (isset($proxyPort)) {
|
||||||
$proxyURL .= ":" . $proxyPort;
|
$proxyURL .= ":" . $proxyPort;
|
||||||
|
} else {
|
||||||
|
if ('http://' == substr($proxyURL, 0, 7)) {
|
||||||
|
$proxyURL .= ":80";
|
||||||
|
} else if ('https://' == substr($proxyURL, 0, 8)) {
|
||||||
|
$proxyURL .= ":443";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// http(s):// is not supported in proxy
|
// http(s):// is not supported in proxy
|
||||||
if ('http://' == substr($proxy, 0, 7)) {
|
$proxyURL = str_replace(array('http://', 'https://'), array('tcp://', 'ssl://'), $proxyURL);
|
||||||
$proxy = 'tcp://' . rtrim(substr($proxy, 7), '/') . (parse_url($proxy, PHP_URL_PORT) ? '' : ':80');
|
|
||||||
} else if ('https://' == substr($proxy, 0, 8)) {
|
|
||||||
$proxy = 'ssl://' . rtrim(substr($proxy, 8), '/') . (parse_url($proxy, PHP_URL_PORT) ? '' : ':443');
|
|
||||||
}
|
|
||||||
|
|
||||||
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(
|
||||||
|
|
|
@ -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