Source for file Proxy.php
Documentation is available at Proxy.php
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
$this->_parseProxyInfo ();
function _parseProxyInfo ()
$this->proxy_host = $this->proxy_port = $this->proxy_user = $this->proxy_pass = '';
if ($this->config->get ('http_proxy')&&
$this->proxy_host = isset ($proxy['host']) ? $proxy['host'] : null;
$this->proxy_port = isset ($proxy['port']) ? $proxy['port'] : 8080;
$this->proxy_user = isset ($proxy['user']) ? urldecode($proxy['user']) : null;
$this->proxy_pass = isset ($proxy['pass']) ? urldecode($proxy['pass']) : null;
$this->proxy_schema = (isset ($proxy['scheme']) && $proxy['scheme'] == 'https') ? 'https' : 'http';
function _httpConnect ($fp, $host, $port)
fwrite($fp, " CONNECT $host:$port HTTP/1.1\r\n" );
fwrite($fp, " Host: $host:$port\r\n" );
if (preg_match('|^HTTP/1.[01] ([0-9]{3}) |', $line, $matches)) {
$code = (int) $matches[1 ];
if ($code < 200 || $code >= 300 ) {
return PEAR::raiseError (" Establishing a CONNECT tunnel through proxy failed with response code $code" );
// connection was successful -- establish SSL through
$crypto_method = STREAM_CRYPTO_METHOD_TLS_CLIENT;
if (defined('STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT')) {
$crypto_method |= STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT;
$crypto_method |= STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT;
// set the correct hostname for working hostname
// blocking socket needed for
// stream_socket_enable_crypto()
// <http://php.net/manual/en/function.stream-socket-enable-crypto.php>
return PEAR::raiseError (" Could not establish SSL connection through proxy $proxy_host:$proxy_port: $crypto_res" );
* get the authorization information for the proxy, encoded to be
* passed in the Proxy-Authentication HTTP header.
* @return null|stringthe encoded authentication information if a
* proxy and authentication is configured, null
return base64_encode($this->proxy_user . ':' . $this->proxy_pass);
return $this->proxy_user;
* Check if we are configured to use a proxy.
* @return boolean true if we are configured to use a proxy, false
return $this->proxy_host != '';
* Open a socket to a remote server, possibly involving a HTTP
* If an HTTP proxy has been configured (http_proxy PEAR_Config
* setting), the proxy will be used.
* @param string $host the host to connect to
* @param string $port the port to connect to
* @param boolean $secure if true, establish a secure connection
function openSocket($host, $port, $secure = false )
$this->proxy_host, $this->proxy_port,
return PEAR::raiseError (" Connection to `$proxy_host:$proxy_port' failed: $errstr" , -9276 );
/* HTTPS is to be used and we have a proxy, use CONNECT verb */
$res = $this->_httpConnect ($fp, $host, $port);
$host = 'ssl://' . $host;
$fp = @fsockopen($host, $port, $errno, $errstr);
return PEAR::raiseError (" Connection to `$host:$port' failed: $errstr" , $errno);
Documentation generated on Sun, 19 Apr 2020 14:22:14 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|