27 #require_once 'Zend/Uri/Http.php'; 31 #require_once 'Zend/Http/Client.php'; 35 #require_once 'Zend/Http/Client/Adapter/Socket.php'; 60 'ssltransport' =>
'ssl',
62 'sslpassphrase' =>
null,
63 'sslusecontext' =>
false,
69 'persistent' =>
false,
96 public function connect($host, $port = 80, $secure =
false)
99 if (!$this->config[
'proxy_host']) {
100 return parent::connect($host, $port, $secure);
105 $this->config[
'sslusecontext'] =
true;
109 return parent::connect(
110 $this->config[
'proxy_host'],
111 $this->config[
'proxy_port'],
128 $method, $uri, $http_ver =
'1.1', $headers = array(), $body =
'' 132 if (!$this->config[
'proxy_host']) {
133 return parent::write(
$method, $uri, $http_ver, $headers, $body);
137 if (!$this->socket) {
138 #require_once 'Zend/Http/Client/Adapter/Exception.php'; 140 'Trying to write but we are not connected' 144 $host = $this->config[
'proxy_host'];
145 $port = $this->config[
'proxy_port'];
147 if ($this->connected_to[0] !=
"tcp://$host" 148 || $this->connected_to[1] != $port
150 #require_once 'Zend/Http/Client/Adapter/Exception.php'; 152 'Trying to write but we are connected to the wrong proxy server' 157 if ($this->config[
'proxy_user']) {
159 $hasProxyAuthHeader =
false;
160 foreach ($headers as $k => $v) {
161 if ((
string) $k ==
'proxy-authorization' 162 || preg_match(
"/^proxy-authorization:/i", $v)
164 $hasProxyAuthHeader =
true;
168 if (!$hasProxyAuthHeader) {
169 $headers[] =
'Proxy-authorization: ' 171 $this->config[
'proxy_user'],
172 $this->config[
'proxy_pass'], $this->config[
'proxy_auth']
180 $uri->getHost(), $uri->getPort(), $http_ver, $headers
182 $this->negotiated =
true;
189 if ($this->negotiated) {
190 $path = $uri->getPath();
191 if ($uri->getQuery()) {
192 $path .=
'?' . $uri->getQuery();
194 $request =
"$method $path HTTP/$http_ver\r\n";
196 $request =
"$method $uri HTTP/$http_ver\r\n";
200 foreach ($headers as $k => $v) {
201 if (is_string($k)) $v =
"$k: $v";
214 #require_once 'Zend/Http/Client/Adapter/Exception.php'; 216 'Error writing request to proxy server' 221 if(stream_copy_to_stream($body, $this->socket) == 0) {
222 #require_once 'Zend/Http/Client/Adapter/Exception.php'; 224 'Error writing request to server' 243 $host, $port = 443, $http_ver =
'1.1', array &$headers = array()
246 $request =
"CONNECT $host:$port HTTP/$http_ver\r\n" .
247 "Host: " . $host .
"\r\n";
250 foreach ($headers as $k => $v) {
251 switch (strtolower(substr($v,0,strpos($v,
':')))) {
252 case 'proxy-authorization':
266 $this->connectHandshakeRequest =
$request;
270 #require_once 'Zend/Http/Client/Adapter/Exception.php'; 272 'Error writing request to proxy server' 279 while ($line = @fgets($this->socket)) {
280 $gotStatus = $gotStatus || (strpos($line,
'HTTP') !==
false);
291 #require_once 'Zend/Http/Client/Adapter/Exception.php'; 293 'Unable to connect to HTTPS proxy. Server response: ' .
$response 301 STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT
305 foreach($modes as
$mode) {
306 $success = stream_socket_enable_crypto($this->socket,
true,
$mode);
313 #require_once 'Zend/Http/Client/Adapter/Exception.php'; 315 'Unable to connect to HTTPS server through proxy: could not ' 316 .
'negotiate secure connection.' 328 $this->negotiated =
false;
connect($host, $port=80, $secure=false)
write( $method, $uri, $http_ver='1.1', $headers=array(), $body='')
connectHandshake( $host, $port=443, $http_ver='1.1', array &$headers=array())
if($exist=($block->getProductCollection() && $block->getProductCollection() ->getSize())) $mode
static encodeAuthHeader($user, $password, $type=self::AUTH_BASIC)
static extractCode($response_str)