00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 class Varien_Http_Adapter_Curl implements Zend_Http_Client_Adapter_Interface
00035 {
00036
00037
00038
00039
00040
00041 protected $_config = array();
00042
00043 protected $_resource;
00044
00045
00046
00047
00048
00049
00050 public function setConfig($config = array())
00051 {
00052 $this->_config = $config;
00053 return $this;
00054 }
00055
00056
00057
00058
00059
00060
00061
00062
00063 public function connect($host, $port = 80, $secure = false)
00064 {
00065
00066 if (isset($this->_config['timeout'])) {
00067 curl_setopt($this->_getResource(), CURLOPT_TIMEOUT, $this->_config['timeout']);
00068 }
00069 if (isset($this->_config['maxredirects'])) {
00070 curl_setopt($this->_getResource(), CURLOPT_MAXREDIRS, $this->_config['maxredirects']);
00071 }
00072 if (isset($this->_config['proxy'])) {
00073 curl_setopt ($this->_getResource(), CURLOPT_PROXY, $this->_config['proxy']);
00074 }
00075
00076 return $this;
00077 }
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089 public function write($method, $url, $http_ver = '1.1', $headers = array(), $body = '')
00090 {
00091 if ($url instanceof Zend_Uri_Http) {
00092 $url = $url->getUri();
00093 }
00094
00095 curl_setopt($this->_getResource(), CURLOPT_URL, $url);
00096 curl_setopt($this->_getResource(), CURLOPT_RETURNTRANSFER, true);
00097 if ($method == Zend_Http_Client::POST) {
00098 curl_setopt($this->_getResource(), CURLOPT_POST, true);
00099 curl_setopt($this->_getResource(), CURLOPT_POSTFIELDS, $body);
00100 }
00101 elseif ($method == Zend_Http_Client::GET) {
00102 curl_setopt($this->_getResource(), CURLOPT_HTTPGET, true);
00103 }
00104
00105 if( is_array($headers) ) {
00106 curl_setopt($this->_getResource(), CURLOPT_HTTPHEADER, $headers);
00107 }
00108
00109 curl_setopt($this->_getResource(), CURLOPT_HEADER, true);
00110 curl_setopt($this->_getResource(), CURLOPT_SSL_VERIFYPEER, 0);
00111 curl_setopt($this->_getResource(), CURLOPT_SSL_VERIFYHOST, 0);
00112
00113
00114 return $body;
00115 }
00116
00117
00118
00119
00120
00121
00122 public function read()
00123 {
00124 $response = curl_exec($this->_getResource());
00125
00126
00127 if (Zend_Http_Response::extractCode($response) == 100 ||
00128 Zend_Http_Response::extractCode($response) == 101) {
00129 $response = preg_split('/^\r?$/m', $response, 2);
00130 $response = trim($response[1]);
00131 }
00132
00133 return $response;
00134 }
00135
00136
00137
00138
00139
00140 public function close()
00141 {
00142 curl_close($this->_getResource());
00143 $this->_resource = null;
00144 return $this;
00145 }
00146
00147 protected function _getResource()
00148 {
00149 if (is_null($this->_resource)) {
00150 $this->_resource = curl_init();
00151 }
00152 return $this->_resource;
00153 }
00154
00155 public function getErrno()
00156 {
00157 return curl_errno($this->_getResource());
00158 }
00159
00160 public function getError()
00161 {
00162 return curl_error($this->_getResource());
00163 }
00164
00165
00166
00167
00168
00169
00170
00171 public function getInfo($opt = 0)
00172 {
00173 return curl_getinfo($this->_getResource(), $opt);
00174 }
00175 }