1
0
Fork 0

Add SNI settings for SSL URLs that are proxied, fixes #3204

pull/3523/merge
Jordi Boggiano 2014-12-12 12:25:21 +00:00
parent 7b13507dd4
commit 8dad846613
2 changed files with 41 additions and 15 deletions

View File

@ -93,6 +93,14 @@ final class StreamContextFactory
break; break;
} }
// add SNI opts for https URLs
if ('https' === parse_url($url, PHP_URL_SCHEME)) {
$options['ssl']['SNI_enabled'] = true;
if (version_compare(PHP_VERSION, '5.6.0', '<')) {
$options['ssl']['SNI_server_name'] = parse_url($url, PHP_URL_HOST);
}
}
// handle proxy auth if present // handle proxy auth if present
if (isset($proxy['user'])) { if (isset($proxy['user'])) {
$auth = urldecode($proxy['user']); $auth = urldecode($proxy['user']);

View File

@ -133,14 +133,23 @@ class StreamContextFactoryTest extends \PHPUnit_Framework_TestCase
$context = StreamContextFactory::getContext('https://example.org', array('http' => array('method' => 'GET'))); $context = StreamContextFactory::getContext('https://example.org', array('http' => array('method' => 'GET')));
$options = stream_context_get_options($context); $options = stream_context_get_options($context);
$this->assertEquals(array('http' => array( $expected = array(
'proxy' => 'tcp://proxyserver.net:80', 'http' => array(
'request_fulluri' => true, 'proxy' => 'tcp://proxyserver.net:80',
'method' => 'GET', 'request_fulluri' => true,
'header' => array("Proxy-Authorization: Basic " . base64_encode('username:password')), 'method' => 'GET',
'max_redirects' => 20, 'header' => array("Proxy-Authorization: Basic " . base64_encode('username:password')),
'follow_location' => 1, 'max_redirects' => 20,
)), $options); 'follow_location' => 1,
), 'ssl' => array(
'SNI_enabled' => true,
'SNI_server_name' => 'example.org'
)
);
if (version_compare(PHP_VERSION, '5.6.0', '>=')) {
unset($expected['ssl']['SNI_server_name']);
}
$this->assertEquals($expected, $options);
} }
public function testHttpsProxyOverride() public function testHttpsProxyOverride()
@ -151,13 +160,22 @@ class StreamContextFactoryTest extends \PHPUnit_Framework_TestCase
$context = StreamContextFactory::getContext('https://example.org', array('http' => array('method' => 'GET'))); $context = StreamContextFactory::getContext('https://example.org', array('http' => array('method' => 'GET')));
$options = stream_context_get_options($context); $options = stream_context_get_options($context);
$this->assertEquals(array('http' => array( $expected = array(
'proxy' => 'ssl://woopproxy.net:443', 'http' => array(
'request_fulluri' => true, 'proxy' => 'ssl://woopproxy.net:443',
'method' => 'GET', 'request_fulluri' => true,
'max_redirects' => 20, 'method' => 'GET',
'follow_location' => 1, 'max_redirects' => 20,
)), $options); 'follow_location' => 1,
), 'ssl' => array(
'SNI_enabled' => true,
'SNI_server_name' => 'example.org'
)
);
if (version_compare(PHP_VERSION, '5.6.0', '>=')) {
unset($expected['ssl']['SNI_server_name']);
}
$this->assertEquals($expected, $options);
} }
/** /**