diff --git a/lib/Cake/Network/CakeSocket.php b/lib/Cake/Network/CakeSocket.php index d428a74cb64..8b3c92e5f0b 100644 --- a/lib/Cake/Network/CakeSocket.php +++ b/lib/Cake/Network/CakeSocket.php @@ -130,7 +130,7 @@ public function connect() { } $scheme = null; - if (!empty($this->config['protocol']) && strpos($this->config['host'], '://') === false) { + if (!empty($this->config['protocol']) && strpos($this->config['host'], '://') === false && empty($this->config['proxy'])) { $scheme = $this->config['protocol'] . '://'; } @@ -170,6 +170,34 @@ public function connect() { if ($this->connected) { stream_set_timeout($this->connection, $this->config['timeout']); } + + + if (!empty($this->config['request']) && $this->config['request']['uri']['scheme'] == 'https' && !empty($this->config['proxy'])) { + $req = array(); + $req[] = 'CONNECT '. $this->config['request']['uri']['host'] . ':' . $this->config['request']['uri']['port'] . ' HTTP/1.1'; + $req[] = 'Host: ' . $this->config['host']; + $req[] = 'User-Agent: php proxy'; + + fwrite($this->connection, implode("\r\n", $req)."\r\n\r\n"); + + while(true) { + $s = rtrim(fgets($this->connection, 4096)); + if(preg_match('/^$/', $s)) { + break; + } + } + + $modes = array(STREAM_CRYPTO_METHOD_TLS_CLIENT, + STREAM_CRYPTO_METHOD_SSLv3_CLIENT, + STREAM_CRYPTO_METHOD_SSLv23_CLIENT, + STREAM_CRYPTO_METHOD_SSLv2_CLIENT); + $success = false; + foreach($modes as $mode) { + $success = stream_socket_enable_crypto($this->connection, true, $mode); + if ($success) break; + } + } + return $this->connected; } diff --git a/lib/Cake/Network/Http/HttpSocket.php b/lib/Cake/Network/Http/HttpSocket.php index 16fc0edcfc2..ff176359f92 100644 --- a/lib/Cake/Network/Http/HttpSocket.php +++ b/lib/Cake/Network/Http/HttpSocket.php @@ -652,6 +652,7 @@ protected function _setProxy() { } $this->config['host'] = $this->_proxy['host']; $this->config['port'] = $this->_proxy['port']; + $this->config['proxy'] = true; if (empty($this->_proxy['method']) || !isset($this->_proxy['user'], $this->_proxy['pass'])) { return;