Skip to content

Commit

Permalink
Addapted quick hack from issue #2057 for 2.6.3
Browse files Browse the repository at this point in the history
  • Loading branch information
RichieB2B authored and markstory committed Mar 24, 2015
1 parent 07de23a commit 54a3f87
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
30 changes: 29 additions & 1 deletion lib/Cake/Network/CakeSocket.php
Expand Up @@ -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'] . '://';
}

Expand Down Expand Up @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions lib/Cake/Network/Http/HttpSocket.php
Expand Up @@ -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;
Expand Down

0 comments on commit 54a3f87

Please sign in to comment.