web/lib/Zend/Http/Client/Adapter/Curl.php
changeset 1230 68c69c656a2c
parent 807 877f952ae2bd
equal deleted inserted replaced
1229:5a6b6e770365 1230:68c69c656a2c
    14  * to license@zend.com so we can send you a copy immediately.
    14  * to license@zend.com so we can send you a copy immediately.
    15  *
    15  *
    16  * @category   Zend
    16  * @category   Zend
    17  * @package    Zend_Http
    17  * @package    Zend_Http
    18  * @subpackage Client_Adapter
    18  * @subpackage Client_Adapter
    19  * @version    $Id: Curl.php 24593 2012-01-05 20:35:02Z matthew $
    19  * @version    $Id$
    20  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    20  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
    21  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    21  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    22  */
    22  */
    23 
    23 
    24 /**
    24 /**
    25  * @see Zend_Uri_Http
    25  * @see Zend_Uri_Http
    40  * Curl requires libcurl. See for full requirements the PHP manual: http://php.net/curl
    40  * Curl requires libcurl. See for full requirements the PHP manual: http://php.net/curl
    41  *
    41  *
    42  * @category   Zend
    42  * @category   Zend
    43  * @package    Zend_Http
    43  * @package    Zend_Http
    44  * @subpackage Client_Adapter
    44  * @subpackage Client_Adapter
    45  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    45  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
    46  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    46  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    47  */
    47  */
    48 class Zend_Http_Client_Adapter_Curl implements Zend_Http_Client_Adapter_Interface, Zend_Http_Client_Adapter_Stream
    48 class Zend_Http_Client_Adapter_Curl implements Zend_Http_Client_Adapter_Interface, Zend_Http_Client_Adapter_Stream
    49 {
    49 {
    50     /**
    50     /**
   220         if ($port != 80) {
   220         if ($port != 80) {
   221             curl_setopt($this->_curl, CURLOPT_PORT, intval($port));
   221             curl_setopt($this->_curl, CURLOPT_PORT, intval($port));
   222         }
   222         }
   223 
   223 
   224         // Set timeout
   224         // Set timeout
   225         curl_setopt($this->_curl, CURLOPT_CONNECTTIMEOUT, $this->_config['timeout']);
   225         if (defined('CURLOPT_CONNECTTIMEOUT_MS')) {
       
   226             curl_setopt($this->_curl, CURLOPT_CONNECTTIMEOUT_MS, $this->_config['timeout'] * 1000);
       
   227         } else {
       
   228             curl_setopt($this->_curl, CURLOPT_CONNECTTIMEOUT, $this->_config['timeout']);
       
   229         }
       
   230 
       
   231         if (defined('CURLOPT_TIMEOUT_MS')) {
       
   232             curl_setopt($this->_curl, CURLOPT_TIMEOUT_MS, $this->_config['timeout'] * 1000);
       
   233         } else {
       
   234             curl_setopt($this->_curl, CURLOPT_TIMEOUT, $this->_config['timeout']);
       
   235         }
   226 
   236 
   227         // Set Max redirects
   237         // Set Max redirects
   228         curl_setopt($this->_curl, CURLOPT_MAXREDIRS, $this->_config['maxredirects']);
   238         curl_setopt($this->_curl, CURLOPT_MAXREDIRS, $this->_config['maxredirects']);
   229 
   239 
   230         if (!$this->_curl) {
   240         if (!$this->_curl) {
   318                     $curlMethod = CURLOPT_CUSTOMREQUEST;
   328                     $curlMethod = CURLOPT_CUSTOMREQUEST;
   319                     $curlValue = "PUT";
   329                     $curlValue = "PUT";
   320                 }
   330                 }
   321                 break;
   331                 break;
   322 
   332 
       
   333             case Zend_Http_Client::PATCH:
       
   334                 $curlMethod = CURLOPT_CUSTOMREQUEST;
       
   335                 $curlValue = "PATCH";
       
   336                 break;
       
   337 
   323             case Zend_Http_Client::DELETE:
   338             case Zend_Http_Client::DELETE:
   324                 $curlMethod = CURLOPT_CUSTOMREQUEST;
   339                 $curlMethod = CURLOPT_CUSTOMREQUEST;
   325                 $curlValue = "DELETE";
   340                 $curlValue = "DELETE";
   326                 break;
   341                 break;
   327 
   342 
   353 
   368 
   354         // get http version to use
   369         // get http version to use
   355         $curlHttp = ($httpVersion == 1.1) ? CURL_HTTP_VERSION_1_1 : CURL_HTTP_VERSION_1_0;
   370         $curlHttp = ($httpVersion == 1.1) ? CURL_HTTP_VERSION_1_1 : CURL_HTTP_VERSION_1_0;
   356 
   371 
   357         // mark as HTTP request and set HTTP method
   372         // mark as HTTP request and set HTTP method
   358         curl_setopt($this->_curl, $curlHttp, true);
   373         curl_setopt($this->_curl, CURLOPT_HTTP_VERSION, $curlHttp);
   359         curl_setopt($this->_curl, $curlMethod, $curlValue);
   374         curl_setopt($this->_curl, $curlMethod, $curlValue);
   360 
   375 
   361         if($this->out_stream) {
   376         if($this->out_stream) {
   362             // headers will be read into the response
   377             // headers will be read into the response
   363             curl_setopt($this->_curl, CURLOPT_HEADER, false);
   378             curl_setopt($this->_curl, CURLOPT_HEADER, false);
   365             // and data will be written into the file
   380             // and data will be written into the file
   366             curl_setopt($this->_curl, CURLOPT_FILE, $this->out_stream);
   381             curl_setopt($this->_curl, CURLOPT_FILE, $this->out_stream);
   367         } else {
   382         } else {
   368             // ensure headers are also returned
   383             // ensure headers are also returned
   369             curl_setopt($this->_curl, CURLOPT_HEADER, true);
   384             curl_setopt($this->_curl, CURLOPT_HEADER, true);
       
   385             curl_setopt($this->_curl, CURLINFO_HEADER_OUT, true);
   370 
   386 
   371             // ensure actual response is returned
   387             // ensure actual response is returned
   372             curl_setopt($this->_curl, CURLOPT_RETURNTRANSFER, true);
   388             curl_setopt($this->_curl, CURLOPT_RETURNTRANSFER, true);
   373         }
   389         }
   374 
   390 
   391             unset($this->_config['curloptions'][CURLOPT_INFILE]);
   407             unset($this->_config['curloptions'][CURLOPT_INFILE]);
   392             unset($this->_config['curloptions'][CURLOPT_INFILESIZE]);
   408             unset($this->_config['curloptions'][CURLOPT_INFILESIZE]);
   393         } elseif ($method == Zend_Http_Client::PUT) {
   409         } elseif ($method == Zend_Http_Client::PUT) {
   394             // This is a PUT by a setRawData string, not by file-handle
   410             // This is a PUT by a setRawData string, not by file-handle
   395             curl_setopt($this->_curl, CURLOPT_POSTFIELDS, $body);
   411             curl_setopt($this->_curl, CURLOPT_POSTFIELDS, $body);
       
   412         } elseif ($method == Zend_Http_Client::PATCH) {
       
   413             // This is a PATCH by a setRawData string
       
   414             curl_setopt($this->_curl, CURLOPT_POSTFIELDS, $body);
   396         } elseif ($method == Zend_Http_Client::DELETE) {
   415         } elseif ($method == Zend_Http_Client::DELETE) {
   397             // This is a DELETE by a setRawData string
   416             // This is a DELETE by a setRawData string
       
   417             curl_setopt($this->_curl, CURLOPT_POSTFIELDS, $body);
       
   418         } elseif ($method == Zend_Http_Client::OPTIONS) {
       
   419             // This is an OPTIONS by a setRawData string
   398             curl_setopt($this->_curl, CURLOPT_POSTFIELDS, $body);
   420             curl_setopt($this->_curl, CURLOPT_POSTFIELDS, $body);
   399         }
   421         }
   400 
   422 
   401         // set additional curl options
   423         // set additional curl options
   402         if (isset($this->_config['curloptions'])) {
   424         if (isset($this->_config['curloptions'])) {