Pārlūkot izejas kodu

ZF-6933 - cURL Adapter now processes the same configuration options like proxy and handles them equally.

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@16501 44c647ce-9c0f-0410-b52a-842ac1e357ba
beberlei 16 gadi atpakaļ
vecāks
revīzija
db051688a8

+ 2 - 1
documentation/manual/en/module_specs/Zend_Http_Client-Adapters.xml

@@ -422,7 +422,8 @@ $client = new Zend_Http_Client($uri, $config);
 
 
         <para>
         <para>
             By default the cURL adapter is configured to behave exactly like
             By default the cURL adapter is configured to behave exactly like
-            the Socket Adapter. You can change the cURL options by either specifying
+            the Socket Adapter and it also accepts the same configuration parameters 
+            as the Socket and Proxy adapters. You can also change the cURL options by either specifying
             the 'curloptions' key in the constructor of the adapter or by calling
             the 'curloptions' key in the constructor of the adapter or by calling
             <code>setCurlOption($name, $value)</code>. The <code>$name</code> key
             <code>setCurlOption($name, $value)</code>. The <code>$name</code> key
             corresponds to the CURL_* constants of the cURL extension. You can
             corresponds to the CURL_* constants of the cURL extension. You can

+ 17 - 1
library/Zend/Http/Client/Adapter/Curl.php

@@ -120,8 +120,24 @@ class Zend_Http_Client_Adapter_Curl implements Zend_Http_Client_Adapter_Interfac
             throw new Zend_Http_Client_Adapter_Exception('Http Adapter configuration expects an array, ' . gettype($config) . ' recieved.');
             throw new Zend_Http_Client_Adapter_Exception('Http Adapter configuration expects an array, ' . gettype($config) . ' recieved.');
         }
         }
 
 
+        if(isset($config['proxy_user']) && isset($config['proxy_pass'])) {
+            $this->setCurlOption(CURLOPT_PROXYUSERPWD, $config['proxy_user'].":".$config['proxy_pass']);
+            unset($config['proxy_user'], $config['proxy_pass']);
+        }
+
         foreach ($config as $k => $v) {
         foreach ($config as $k => $v) {
-            $this->_config[strtolower($k)] = $v;
+            $option = strtolower($k);
+            switch($option) {
+                case 'proxy_host':
+                    $this->setCurlOption(CURLOPT_PROXY, $v);
+                    break;
+                case 'proxy_port':
+                    $this->setCurlOption(CURLOPT_PROXYPORT, $v);
+                    break;
+                default:
+                    $this->_config[$option] = $v;
+                    break;
+            }
         }
         }
 
 
         return $this;
         return $this;

+ 23 - 0
tests/Zend/Http/Client/CurlTest.php

@@ -185,6 +185,29 @@ class Zend_Http_Client_CurlTest extends Zend_Http_Client_SocketTest
         );
         );
     }
     }
 
 
+    public function testWorkWithProxyConfiguration()
+    {
+        $adapter = new Zend_Http_Client_Adapter_Curl();
+        $adapter->setConfig(array(
+            'proxy_host' => 'localhost',
+            'proxy_port' => 80,
+            'proxy_user' => 'foo',
+            'proxy_pass' => 'baz',
+        ));
+
+        $expected = array(
+            'curloptions' => array(
+                CURLOPT_PROXYUSERPWD => 'foo:baz',
+                CURLOPT_PROXY => 'localhost',
+                CURLOPT_PROXYPORT => 80,
+            ),
+        );
+
+        $this->assertEquals(
+            $expected, $this->readAttribute($adapter, '_config')
+        );
+    }
+
     /**
     /**
      * @group ZF-7040
      * @group ZF-7040
      */
      */