예제 #1
0
 /**
  * Proxify an existing client.
  *
  * Returns the client given as argument with appropriate proxy setup.
  *
  * @param \Zend\Http\Client $client  HTTP client
  * @param array             $options ZF2 ProxyAdapter options
  *
  * @return \Zend\Http\Client
  */
 public function proxify(\Zend\Http\Client $client, array $options = [])
 {
     if ($this->proxyConfig) {
         $host = $client->getUri()->getHost();
         if (!$this->isLocal($host)) {
             $proxyType = isset($this->proxyConfig['proxy_type']) ? $this->proxyConfig['proxy_type'] : 'default';
             if ($proxyType == 'socks5') {
                 $adapter = new \Zend\Http\Client\Adapter\Curl();
                 // Apply standard proxy options for Curl adapter:
                 $this->setCurlProxyOptions($adapter);
                 // Add SOCKS5 settings:
                 $adapter->setCurlOption(CURLOPT_FOLLOWLOCATION, true);
                 $adapter->setCurlOption(CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
                 $client->setAdapter($adapter);
             } elseif ($proxyType == 'default') {
                 // If the user has manually configured a Curl adapter,
                 // configure it for proxy compatibility; otherwise, create
                 // a fresh Proxy adapter.
                 if ($this->hasCurlAdapterAsDefault()) {
                     $adapter = new \Zend\Http\Client\Adapter\Curl();
                     $this->setCurlProxyOptions($adapter);
                 } else {
                     $adapter = new \Zend\Http\Client\Adapter\Proxy();
                     $options = array_replace($this->proxyConfig, $options);
                     $adapter->setOptions($options);
                 }
                 $client->setAdapter($adapter);
             }
         }
     }
     return $client;
 }
예제 #2
0
 /**
  * Proxify an existing client.
  *
  * Returns the client given as argument with appropriate proxy setup.
  *
  * @param \Zend\Http\Client $client  HTTP client
  * @param array             $options ZF2 ProxyAdapter options
  *
  * @return \Zend\Http\Client
  */
 public function proxify(\Zend\Http\Client $client, array $options = array())
 {
     if ($this->proxyConfig) {
         $host = $client->getUri()->getHost();
         if (!$this->isLocal($host)) {
             $adapter = new \Zend\Http\Client\Adapter\Proxy();
             $options = array_replace($this->proxyConfig, $options);
             $adapter->setOptions($options);
             $client->setAdapter($adapter);
         }
     }
     return $client;
 }
예제 #3
0
 /**
  * Proxify an existing client.
  *
  * Returns the client given as argument with appropriate proxy setup.
  *
  * @param \Zend\Http\Client $client  HTTP client
  * @param array             $options ZF2 ProxyAdapter options
  *
  * @return \Zend\Http\Client
  */
 public function proxify(\Zend\Http\Client $client, array $options = array())
 {
     if ($this->proxyConfig) {
         $host = $client->getUri()->getHost();
         if (!$this->isLocal($host)) {
             $proxyType = isset($this->proxyConfig['proxy_type']) ? $this->proxyConfig['proxy_type'] : 'default';
             if ($proxyType == 'socks5') {
                 $adapter = new \Zend\Http\Client\Adapter\Curl();
                 $host = $this->proxyConfig['proxy_host'];
                 $port = $this->proxyConfig['proxy_port'];
                 $adapter->setCurlOption(CURLOPT_FOLLOWLOCATION, true);
                 $adapter->setCurlOption(CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
                 $adapter->setCurlOption(CURLOPT_PROXY, $host);
                 if (isset($port) && !empty($port)) {
                     $adapter->setCurlOption(CURLOPT_PROXYPORT, $port);
                 }
                 $client->setAdapter($adapter);
             } elseif ($proxyType == 'default') {
                 $adapter = new \Zend\Http\Client\Adapter\Proxy();
                 $options = array_replace($this->proxyConfig, $options);
                 $adapter->setOptions($options);
                 $client->setAdapter($adapter);
             }
         }
     }
     return $client;
 }