1
0
Fork 0

Solving the issue #1387

pull/1388/head
Fernando Mantoan 2012-12-05 12:22:24 -02:00
parent 07f7487c60
commit 0f337dd56a
2 changed files with 23 additions and 2 deletions

View File

@ -67,12 +67,19 @@ final class StreamContextFactory
$auth .= ':' . $proxy['pass']; $auth .= ':' . $proxy['pass'];
} }
$auth = base64_encode($auth); $auth = base64_encode($auth);
$authHeader = "Proxy-Authorization: Basic {$auth}";
// Preserve headers if already set in default options // Preserve headers if already set in default options
if (isset($defaultOptions['http']['header'])) { if (isset($defaultOptions['http']['header'])) {
$defaultOptions['http']['header'][] = "Proxy-Authorization: Basic {$auth}"; if (is_array($defaultOptions['http']['header']))
$defaultOptions['http']['header'][] = $authHeader;
else
$defaultOptions['http']['header'] = array(
$defaultOptions['http']['header'],
$authHeader
);
} else { } else {
$options['http']['header'] = array("Proxy-Authorization: Basic {$auth}"); $options['http']['header'] = array($authHeader);
} }
} }
} }

View File

@ -126,6 +126,20 @@ class StreamContextFactoryTest extends \PHPUnit_Framework_TestCase
} }
} }
public function testHttpProxyWithContentTypeHeader() {
$_SERVER['http_proxy'] = 'http://username:password@proxyserver.net';
$context = StreamContextFactory::getContext(array('http' => array('method' => 'GET', 'header' => 'Content-Type: application/json')));
$options = stream_context_get_options($context);
$this->assertEquals(array('http' => array(
'proxy' => 'tcp://proxyserver.net:80',
'request_fulluri' => true,
'method' => 'GET',
'header' => array("Content-Type: application/json", "Proxy-Authorization: Basic " . base64_encode('username:password'))
)), $options);
}
public function dataSSLProxy() public function dataSSLProxy()
{ {
return array( return array(