From df592d40de7579d47aeb3d778a2b818bb16d2f5f Mon Sep 17 00:00:00 2001 From: Fernando Mantoan Date: Wed, 5 Dec 2012 12:35:10 -0200 Subject: [PATCH] Solving the issue #1387 --- src/Composer/Installer/InstallationManager.php | 4 ++-- src/Composer/Util/StreamContextFactory.php | 11 ++--------- .../Test/Util/StreamContextFactoryTest.php | 14 -------------- 3 files changed, 4 insertions(+), 25 deletions(-) diff --git a/src/Composer/Installer/InstallationManager.php b/src/Composer/Installer/InstallationManager.php index 3aa4be7c6..55e1eef4b 100644 --- a/src/Composer/Installer/InstallationManager.php +++ b/src/Composer/Installer/InstallationManager.php @@ -245,7 +245,7 @@ class InstallationManager $opts = array('http' => array( 'method' => 'POST', - 'header' => 'Content-type: application/x-www-form-urlencoded', + 'header' => array('Content-type: application/x-www-form-urlencoded'), 'content' => http_build_query($params, '', '&'), 'timeout' => 3, ) @@ -269,7 +269,7 @@ class InstallationManager $opts = array('http' => array( 'method' => 'POST', - 'header' => 'Content-Type: application/json', + 'header' => array('Content-Type: application/json'), 'content' => json_encode($postData), 'timeout' => 6, ) diff --git a/src/Composer/Util/StreamContextFactory.php b/src/Composer/Util/StreamContextFactory.php index 590bed581..5c335ce9c 100644 --- a/src/Composer/Util/StreamContextFactory.php +++ b/src/Composer/Util/StreamContextFactory.php @@ -67,19 +67,12 @@ final class StreamContextFactory $auth .= ':' . $proxy['pass']; } $auth = base64_encode($auth); - $authHeader = "Proxy-Authorization: Basic {$auth}"; // Preserve headers if already set in default options if (isset($defaultOptions['http']['header'])) { - if (is_array($defaultOptions['http']['header'])) - $defaultOptions['http']['header'][] = $authHeader; - else - $defaultOptions['http']['header'] = array( - $defaultOptions['http']['header'], - $authHeader - ); + $defaultOptions['http']['header'][] = "Proxy-Authorization: Basic {$auth}"; } else { - $options['http']['header'] = array($authHeader); + $options['http']['header'] = array("Proxy-Authorization: Basic {$auth}"); } } } diff --git a/tests/Composer/Test/Util/StreamContextFactoryTest.php b/tests/Composer/Test/Util/StreamContextFactoryTest.php index 5d7969660..3d728ffeb 100644 --- a/tests/Composer/Test/Util/StreamContextFactoryTest.php +++ b/tests/Composer/Test/Util/StreamContextFactoryTest.php @@ -126,20 +126,6 @@ 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() { return array(