From 11dc50745ef0af523e02934c707ec32fb0b9cc03 Mon Sep 17 00:00:00 2001 From: Brian Gallagher Date: Wed, 7 Nov 2012 11:48:02 +0000 Subject: [PATCH] fixed proxy keys being incorrectly set due to normalising in Zend\Http\Client --- library/Zend/Http/Client/Adapter/Proxy.php | 18 +++++++++++++++ .../ZendTest/Http/Client/ProxyAdapterTest.php | 23 +++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/library/Zend/Http/Client/Adapter/Proxy.php b/library/Zend/Http/Client/Adapter/Proxy.php index 195718bdae7..edf11d7c415 100644 --- a/library/Zend/Http/Client/Adapter/Proxy.php +++ b/library/Zend/Http/Client/Adapter/Proxy.php @@ -58,6 +58,24 @@ class Proxy extends Socket */ protected $negotiated = false; + /** + * Set the configuration array for the adapter + * + * @param array $options + */ + public function setOptions($options = array()) + { + //enforcing that the proxy keys are set in the form proxy_* + foreach ($options as $k => $v) { + if (preg_match("/^proxy[a-z]+/", $k)) { + $options['proxy_' . substr($k, 5, strlen($k))] = $v; + unset($options[$k]); + } + } + + parent::setOptions($options); + } + /** * Connect to the remote server * diff --git a/tests/ZendTest/Http/Client/ProxyAdapterTest.php b/tests/ZendTest/Http/Client/ProxyAdapterTest.php index b39e2795bd1..dc19091449f 100644 --- a/tests/ZendTest/Http/Client/ProxyAdapterTest.php +++ b/tests/ZendTest/Http/Client/ProxyAdapterTest.php @@ -28,6 +28,11 @@ */ class ProxyAdapterTest extends SocketTest { + + + protected $host; + protected $port; + /** * Configuration array * @@ -43,6 +48,8 @@ protected function setUp() if (! $host) $this->markTestSkipped('No valid proxy host name or address specified.'); + $this->host = $host; + $port = (int) $port; if ($port == 0) { $port = 8080; @@ -51,6 +58,8 @@ protected function setUp() $this->markTestSkipped("$port is not a valid proxy port number. Should be between 1 and 65535."); } + $this->port = $port; + $user = ''; $pass = ''; if (defined('TESTS_ZEND_HTTP_CLIENT_HTTP_PROXY_USER') && @@ -110,4 +119,18 @@ public function testDefaultConfig() $this->assertEquals(TRUE, $config['sslverifypeer']); $this->assertEquals(FALSE, $config['sslallowselfsigned']); } + + /** + * Test that the proxy keys normalised by the client are correctly converted to what the proxy adapter expects. + */ + public function testProxyKeysCorrectlySetInProxyAdapter() + { + $adapterConfig = $this->_adapter->getConfig(); + $adapterHost = $adapterConfig['proxy_host']; + $adapterPort = $adapterConfig['proxy_port']; + + $this->assertSame($this->host, $adapterHost); + $this->assertSame($this->port, $adapterPort); + } + }