Skip to content

Commit

Permalink
Move proxy code inside if (->connected)
Browse files Browse the repository at this point in the history
  • Loading branch information
RichieB2B authored and markstory committed Mar 24, 2015
1 parent 7704efd commit 15c80f7
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions lib/Cake/Network/CakeSocket.php
Expand Up @@ -169,26 +169,25 @@ public function connect() {
$this->connected = is_resource($this->connection);
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';
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");
fwrite($this->connection, implode("\r\n", $req) . "\r\n\r\n");

while (!feof($this->connection)) {
$s = rtrim(fgets($this->connection, 4096));
if (preg_match('/^$/', $s)) {
break;
while (!feof($this->connection)) {
$s = rtrim(fgets($this->connection, 4096));
if (preg_match('/^$/', $s)) {
break;
}
}
}

$this->enableCrypto('tls', 'client');
$this->enableCrypto('tls', 'client');
}
}

return $this->connected;
}

Expand Down

0 comments on commit 15c80f7

Please sign in to comment.