Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 132 deletions.
4 changes: 2 additions & 2 deletions src/Client/Adapter/AdapterInterface.php
Expand Up @@ -43,12 +43,12 @@ public function connect($host, $port = 80, $secure = false);
*
* @param string $method
* @param \Zend\Uri\Uri $url
* @param string $http_ver
* @param string $httpVer
* @param array $headers
* @param string $body
* @return string Request as text
*/
public function write($method, $url, $http_ver = '1.1', $headers = array(), $body = '');
public function write($method, $url, $httpVer = '1.1', $headers = array(), $body = '');

/**
* Read response from server
Expand Down
20 changes: 10 additions & 10 deletions src/Client/Adapter/Proxy.php
Expand Up @@ -113,16 +113,16 @@ public function connect($host, $port = 80, $secure = false)
*
* @param string $method
* @param \Zend\Uri\Uri $uri
* @param string $http_ver
* @param string $httpVer
* @param array $headers
* @param string $body
* @throws AdapterException\RuntimeException
* @return string Request as string
*/
public function write($method, $uri, $http_ver = '1.1', $headers = array(), $body = '')
public function write($method, $uri, $httpVer = '1.1', $headers = array(), $body = '')
{
// If no proxy is set, fall back to default Socket adapter
if (! $this->config['proxy_host']) return parent::write($method, $uri, $http_ver, $headers, $body);
if (! $this->config['proxy_host']) return parent::write($method, $uri, $httpVer, $headers, $body);

// Make sure we're properly connected
if (! $this->socket) {
Expand All @@ -132,7 +132,7 @@ public function write($method, $uri, $http_ver = '1.1', $headers = array(), $bod
$host = $this->config['proxy_host'];
$port = $this->config['proxy_port'];

if ($this->connected_to[0] != "tcp://$host" || $this->connected_to[1] != $port) {
if ($this->connectedTo[0] != "tcp://$host" || $this->connectedTo[1] != $port) {
throw new AdapterException\RuntimeException("Trying to write but we are connected to the wrong proxy server");
}

Expand All @@ -145,7 +145,7 @@ public function write($method, $uri, $http_ver = '1.1', $headers = array(), $bod

// if we are proxying HTTPS, preform CONNECT handshake with the proxy
if ($uri->getScheme() == 'https' && (! $this->negotiated)) {
$this->connectHandshake($uri->getHost(), $uri->getPort(), $http_ver, $headers);
$this->connectHandshake($uri->getHost(), $uri->getPort(), $httpVer, $headers);
$this->negotiated = true;
}

Expand All @@ -158,9 +158,9 @@ public function write($method, $uri, $http_ver = '1.1', $headers = array(), $bod
if ($uri->getQuery()) {
$path .= '?' . $uri->getQuery();
}
$request = "$method $path HTTP/$http_ver\r\n";
$request = "$method $path HTTP/$httpVer\r\n";
} else {
$request = "$method $uri HTTP/$http_ver\r\n";
$request = "$method $uri HTTP/$httpVer\r\n";
}

// Add all headers to the request string
Expand Down Expand Up @@ -198,13 +198,13 @@ public function write($method, $uri, $http_ver = '1.1', $headers = array(), $bod
*
* @param string $host
* @param integer $port
* @param string $http_ver
* @param string $httpVer
* @param array $headers
* @throws AdapterException\RuntimeException
*/
protected function connectHandshake($host, $port = 443, $http_ver = '1.1', array &$headers = array())
protected function connectHandshake($host, $port = 443, $httpVer = '1.1', array &$headers = array())
{
$request = "CONNECT $host:$port HTTP/$http_ver\r\n" .
$request = "CONNECT $host:$port HTTP/$httpVer\r\n" .
"Host: " . $this->config['proxy_host'] . "\r\n";

// Add the user-agent header
Expand Down
80 changes: 40 additions & 40 deletions src/Client/Adapter/Socket.php
Expand Up @@ -51,14 +51,14 @@ class Socket implements HttpAdapter, StreamInterface
*
* @var array
*/
protected $connected_to = array(null, null);
protected $connectedTo = array(null, null);

/**
* Stream for storing output
*
* @var resource
*/
protected $out_stream = null;
protected $outStream = null;

/**
* Parameters array
Expand Down Expand Up @@ -189,11 +189,11 @@ public function getStreamContext()
public function connect($host, $port = 80, $secure = false)
{
// If we are connected to the wrong host, disconnect first
$connected_host = (strpos($this->connected_to[0], '://'))
? substr($this->connected_to[0], (strpos($this->connected_to[0], '://') + 3), strlen($this->connected_to[0]))
: $this->connected_to[0];
$connectedHost = (strpos($this->connectedTo[0], '://'))
? substr($this->connectedTo[0], (strpos($this->connectedTo[0], '://') + 3), strlen($this->connectedTo[0]))
: $this->connectedTo[0];

if ($connected_host != $host || $this->connected_to[1] != $port) {
if ($connectedHost != $host || $this->connectedTo[1] != $port) {
if (is_resource($this->socket)) {
$this->close();
}
Expand Down Expand Up @@ -313,8 +313,8 @@ public function connect($host, $port = 80, $secure = false)
$host = 'tcp://' . $host;
}

// Update connected_to
$this->connected_to = array($host, $port);
// Update connectedTo
$this->connectedTo = array($host, $port);
}
}

Expand All @@ -324,13 +324,13 @@ public function connect($host, $port = 80, $secure = false)
*
* @param string $method
* @param \Zend\Uri\Uri $uri
* @param string $http_ver
* @param string $httpVer
* @param array $headers
* @param string $body
* @throws AdapterException\RuntimeException
* @return string Request as string
*/
public function write($method, $uri, $http_ver = '1.1', $headers = array(), $body = '')
public function write($method, $uri, $httpVer = '1.1', $headers = array(), $body = '')
{
// Make sure we're properly connected
if (! $this->socket) {
Expand All @@ -339,7 +339,7 @@ public function write($method, $uri, $http_ver = '1.1', $headers = array(), $bod

$host = $uri->getHost();
$host = (strtolower($uri->getScheme()) == 'https' ? $this->config['ssltransport'] : 'tcp') . '://' . $host;
if ($this->connected_to[0] != $host || $this->connected_to[1] != $uri->getPort()) {
if ($this->connectedTo[0] != $host || $this->connectedTo[1] != $uri->getPort()) {
throw new AdapterException\RuntimeException('Trying to write but we are connected to the wrong host');
}

Expand All @@ -349,7 +349,7 @@ public function write($method, $uri, $http_ver = '1.1', $headers = array(), $bod
// Build request headers
$path = $uri->getPath();
if ($uri->getQuery()) $path .= '?' . $uri->getQuery();
$request = "{$method} {$path} HTTP/{$http_ver}\r\n";
$request = "{$method} {$path} HTTP/{$httpVer}\r\n";
foreach ($headers as $k => $v) {
if (is_string($k)) $v = ucfirst($k) . ": $v";
$request .= "$v\r\n";
Expand Down Expand Up @@ -427,11 +427,11 @@ public function read()
}

// If we got a 'transfer-encoding: chunked' header
$transfer_encoding = $headers->get('transfer-encoding');
$content_length = $headers->get('content-length');
if ($transfer_encoding !== false) {
$transferEncoding = $headers->get('transfer-encoding');
$contentLength = $headers->get('content-length');
if ($transferEncoding !== false) {

if (strtolower($transfer_encoding->getFieldValue()) == 'chunked') {
if (strtolower($transferEncoding->getFieldValue()) == 'chunked') {

do {
$line = fgets($this->socket);
Expand All @@ -451,19 +451,19 @@ public function read()
$chunksize = hexdec($chunksize);

// Read next chunk
$read_to = ftell($this->socket) + $chunksize;
$readTo = ftell($this->socket) + $chunksize;

do {
$current_pos = ftell($this->socket);
if ($current_pos >= $read_to) break;
$currentPos = ftell($this->socket);
if ($currentPos >= $readTo) break;

if ($this->out_stream) {
if (stream_copy_to_stream($this->socket, $this->out_stream, $read_to - $current_pos) == 0) {
if ($this->outStream) {
if (stream_copy_to_stream($this->socket, $this->outStream, $readTo - $currentPos) == 0) {
$this->_checkSocketReadTimeout();
break;
}
} else {
$line = fread($this->socket, $read_to - $current_pos);
$line = fread($this->socket, $readTo - $currentPos);
if ($line === false || strlen($line) === 0) {
$this->_checkSocketReadTimeout();
break;
Expand All @@ -477,45 +477,45 @@ public function read()
ErrorHandler::stop();
$this->_checkSocketReadTimeout();

if (!$this->out_stream) {
if (!$this->outStream) {
$response .= $chunk;
}
} while ($chunksize > 0);
} else {
$this->close();
throw new AdapterException\RuntimeException('Cannot handle "' .
$transfer_encoding->getFieldValue() . '" transfer encoding');
$transferEncoding->getFieldValue() . '" transfer encoding');
}

// We automatically decode chunked-messages when writing to a stream
// this means we have to disallow the Zend_Http_Response to do it again
if ($this->out_stream) {
if ($this->outStream) {
$response = str_ireplace("Transfer-Encoding: chunked\r\n", '', $response);
}
// Else, if we got the content-length header, read this number of bytes
} elseif ($content_length !== false) {
} elseif ($contentLength !== false) {

// If we got more than one Content-Length header (see ZF-9404) use
// the last value sent
if (is_array($content_length)) {
$content_length = $content_length[count($content_length) - 1];
if (is_array($contentLength)) {
$contentLength = $contentLength[count($contentLength) - 1];
}
$contentLength = $content_length->getFieldValue();
$contentLength = $contentLength->getFieldValue();

$current_pos = ftell($this->socket);
$currentPos = ftell($this->socket);
$chunk = '';

for ($read_to = $current_pos + $contentLength;
$read_to > $current_pos;
$current_pos = ftell($this->socket)) {
for ($readTo = $currentPos + $contentLength;
$readTo > $currentPos;
$currentPos = ftell($this->socket)) {

if ($this->out_stream) {
if (stream_copy_to_stream($this->socket, $this->out_stream, $read_to - $current_pos) == 0) {
if ($this->outStream) {
if (stream_copy_to_stream($this->socket, $this->outStream, $readTo - $currentPos) == 0) {
$this->_checkSocketReadTimeout();
break;
}
} else {
$chunk = fread($this->socket, $read_to - $current_pos);
$chunk = fread($this->socket, $readTo - $currentPos);
if ($chunk === false || strlen($chunk) === 0) {
$this->_checkSocketReadTimeout();
break;
Expand All @@ -532,8 +532,8 @@ public function read()
} else {

do {
if ($this->out_stream) {
if (stream_copy_to_stream($this->socket, $this->out_stream) == 0) {
if ($this->outStream) {
if (stream_copy_to_stream($this->socket, $this->outStream) == 0) {
$this->_checkSocketReadTimeout();
break;
}
Expand Down Expand Up @@ -573,7 +573,7 @@ public function close()
ErrorHandler::stop();
}
$this->socket = null;
$this->connected_to = array(null, null);
$this->connectedTo = array(null, null);
}

/**
Expand Down Expand Up @@ -605,7 +605,7 @@ protected function _checkSocketReadTimeout()
*/
public function setOutputStream($stream)
{
$this->out_stream = $stream;
$this->outStream = $stream;
return $this;
}

Expand Down
6 changes: 3 additions & 3 deletions src/Client/Adapter/Test.php
Expand Up @@ -122,12 +122,12 @@ public function connect($host, $port = 80, $secure = false)
*
* @param string $method
* @param \Zend\Uri\Uri $uri
* @param string $http_ver
* @param string $httpVer
* @param array $headers
* @param string $body
* @return string Request as string
*/
public function write($method, $uri, $http_ver = '1.1', $headers = array(), $body = '')
public function write($method, $uri, $httpVer = '1.1', $headers = array(), $body = '')
{
$host = $uri->getHost();
$host = (strtolower($uri->getScheme()) == 'https' ? 'sslv2://' . $host : $host);
Expand All @@ -138,7 +138,7 @@ public function write($method, $uri, $http_ver = '1.1', $headers = array(), $bod
$path = '/';
}
if ($uri->getQuery()) $path .= '?' . $uri->getQuery();
$request = "{$method} {$path} HTTP/{$http_ver}\r\n";
$request = "{$method} {$path} HTTP/{$httpVer}\r\n";
foreach ($headers as $k => $v) {
if (is_string($k)) $v = ucfirst($k) . ": $v";
$request .= "$v\r\n";
Expand Down

0 comments on commit e823524

Please sign in to comment.