Permalink
Browse files

fixed proxy keys being incorrectly set due to normalising in Zend\Htt…

…p\Client
  • Loading branch information...
1 parent ef6320a commit 35a3d7450b9c2d6331e562bfc90b99ad2f66ceaa @bgallagher committed Nov 7, 2012
Showing with 41 additions and 0 deletions.
  1. +18 −0 library/Zend/Http/Client/Adapter/Proxy.php
  2. +23 −0 tests/ZendTest/Http/Client/ProxyAdapterTest.php
@@ -59,6 +59,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
*
* Will try to connect to the proxy server. If no proxy was set, will
@@ -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);
+ }
+
}

0 comments on commit 35a3d74

Please sign in to comment.