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

Commit

Permalink
Http
Browse files Browse the repository at this point in the history
  • Loading branch information
mhujer committed Apr 1, 2012
5 parents 2d93aed + d0e7648 + 752a5af + 0332abd + 56b711e commit a42a64f
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 59 deletions.
29 changes: 14 additions & 15 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ public function setCookies($cookies)
if (is_array($cookies)) {
$this->clearCookies();
foreach ($cookies as $name => $value) {
$this->addCookie($name,$value);
$this->addCookie($name, $value);
}
} else {
throw new Exception\InvalidArgumentException('Invalid cookies passed as parameter, it must be an array');
Expand Down Expand Up @@ -607,7 +607,7 @@ protected function openTempStream()
{
$this->streamName = $this->config['outputstream'];

if(!is_string($this->streamName)) {
if (!is_string($this->streamName)) {
// If name is not given, create temp name
$this->streamName = tempnam(
isset($this->config['streamtmpdir']) ? $this->config['streamtmpdir'] : sys_get_temp_dir(),
Expand Down Expand Up @@ -696,9 +696,9 @@ protected function calcAuthDigest($user, $password, $type = self::AUTH_BASIC, $d
$ha2 = md5($this->getMethod() . ':' . $this->getUri()->getPath() . ':' . md5($entityBody));
}
if (empty($digest['qop'])) {
$response = md5 ($ha1 . ':' . $digest['nonce'] . ':' . $ha2);
$response = md5($ha1 . ':' . $digest['nonce'] . ':' . $ha2);
} else {
$response = md5 ($ha1 . ':' . $digest['nonce'] . ':' . $digest['nc']
$response = md5($ha1 . ':' . $digest['nonce'] . ':' . $digest['nc']
. ':' . $digest['cnonce'] . ':' . $digest['qoc'] . ':' . $ha2);
}
break;
Expand Down Expand Up @@ -783,7 +783,7 @@ public function send(Request $request = null)
$queryString = str_replace('+', '%20', $queryString);
}

if (strpos($newUri,'?') !== false) {
if (strpos($newUri, '?') !== false) {
$newUri .= '&' . $queryString;
} else {
$newUri .= '?' . $queryString;
Expand All @@ -804,7 +804,7 @@ public function send(Request $request = null)
$body = $this->prepareBody();

// headers
$headers = $this->prepareHeaders($body,$uri);
$headers = $this->prepareHeaders($body, $uri);

$secure = $uri->getScheme() == 'https';

Expand All @@ -815,7 +815,7 @@ public function send(Request $request = null)
}

// check that adapter supports streaming before using it
if(is_resource($body) && !($this->adapter instanceof Client\Adapter\Stream)) {
if (is_resource($body) && !($this->adapter instanceof Client\Adapter\Stream)) {
throw new Client\Exception\RuntimeException('Adapter does not support streaming');
}

Expand All @@ -833,7 +833,7 @@ public function send(Request $request = null)
$this->lastRawResponse = null;
}

if($this->config['outputstream']) {
if ($this->config['outputstream']) {
$streamMetaData = stream_get_meta_data($stream);
if ($streamMetaData['seekable']) {
rewind($stream);
Expand All @@ -842,7 +842,7 @@ public function send(Request $request = null)
$this->adapter->setOutputStream(null);
$response = Response\Stream::fromStream($response, $stream);
$response->setStreamName($this->streamName);
if(!is_string($this->config['outputstream'])) {
if (!is_string($this->config['outputstream'])) {
// we used temp name, will need to clean up
$response->setCleanup(true);
}
Expand Down Expand Up @@ -888,7 +888,7 @@ public function send(Request $request = null)
$this->getUri()->setQuery($query);

// Else, if we got just an absolute path, set it
if(strpos($location, '/') === 0) {
if (strpos($location, '/') === 0) {
$this->getUri()->setPath($location);
// Else, assume we have a relative path
} else {
Expand Down Expand Up @@ -962,7 +962,7 @@ public function removeFileUpload($filename)
{
$file = $this->getRequest()->file()->get($filename);
if (!empty($file)) {
$this->getRequest()->file()->set($filename,null);
$this->getRequest()->file()->set($filename, null);
return true;
}
return false;
Expand Down Expand Up @@ -1235,8 +1235,7 @@ protected function flattenParametersArray($parray, $prefix = null)

$parameters = array();

foreach($parray as $name => $value) {

foreach ($parray as $name => $value) {
// Calculate array key
if ($prefix) {
if (is_int($name)) {
Expand Down Expand Up @@ -1276,8 +1275,8 @@ protected function doRequest(Http $uri, $method, $secure = false, $headers = arr
// Open the connection, send the request and read the response
$this->adapter->connect($uri->getHost(), $uri->getPort(), $secure);

if($this->config['outputstream']) {
if($this->adapter instanceof Client\Adapter\Stream) {
if ($this->config['outputstream']) {
if ($this->adapter instanceof Client\Adapter\Stream) {
$stream = $this->openTempStream();
$this->adapter->setOutputStream($stream);
} else {
Expand Down
16 changes: 8 additions & 8 deletions src/Client/Adapter/Curl.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public function setConfig($config = array())
$config[str_replace(array('-', '_', ' ', '.'), '', strtolower($k))] = $v; // replace w/ normalized
}

if(isset($config['proxyuser']) && isset($config['proxypass'])) {
if (isset($config['proxyuser']) && isset($config['proxypass'])) {
$this->setCurlOption(CURLOPT_PROXYUSERPWD, $config['proxyuser'].":".$config['proxypass']);
unset($config['proxyuser'], $config['proxypass']);
}
Expand Down Expand Up @@ -283,15 +283,15 @@ public function write($method, $uri, $httpVersion = 1.1, $headers = array(), $bo
case 'PUT' :
// There are two different types of PUT request, either a Raw Data string has been set
// or CURLOPT_INFILE and CURLOPT_INFILESIZE are used.
if(is_resource($body)) {
if (is_resource($body)) {
$this->config['curloptions'][CURLOPT_INFILE] = $body;
}
if (isset($this->config['curloptions'][CURLOPT_INFILE])) {
// Now we will probably already have Content-Length set, so that we have to delete it
// from $headers at this point:
foreach ($headers AS $k => $header) {
if (preg_match('/Content-Length:\s*(\d+)/i', $header, $m)) {
if(is_resource($body)) {
if (is_resource($body)) {
$this->config['curloptions'][CURLOPT_INFILESIZE] = (int)$m[1];
}
unset($headers[$k]);
Expand All @@ -302,7 +302,7 @@ public function write($method, $uri, $httpVersion = 1.1, $headers = array(), $bo
throw new AdapterException\RuntimeException("Cannot set a file-handle for cURL option CURLOPT_INFILE without also setting its size in CURLOPT_INFILESIZE.");
}

if(is_resource($body)) {
if (is_resource($body)) {
$body = '';
}

Expand Down Expand Up @@ -338,7 +338,7 @@ public function write($method, $uri, $httpVersion = 1.1, $headers = array(), $bo
throw new AdapterException\InvalidArgumentException("Method currently not supported");
}

if(is_resource($body) && $curlMethod != CURLOPT_UPLOAD) {
if (is_resource($body) && $curlMethod != CURLOPT_UPLOAD) {
throw new AdapterException\RuntimeException("Streaming requests are allowed only with PUT");
}

Expand All @@ -349,7 +349,7 @@ public function write($method, $uri, $httpVersion = 1.1, $headers = array(), $bo
curl_setopt($this->curl, $curlHttp, true);
curl_setopt($this->curl, $curlMethod, $curlValue);

if($this->outputStream) {
if ($this->outputStream) {
// headers will be read into the response
curl_setopt($this->curl, CURLOPT_HEADER, false);
curl_setopt($this->curl, CURLOPT_HEADERFUNCTION, array($this, "readHeader"));
Expand Down Expand Up @@ -405,7 +405,7 @@ public function write($method, $uri, $httpVersion = 1.1, $headers = array(), $bo
$response = curl_exec($this->curl);

// if we used streaming, headers are already there
if(!is_resource($this->outputStream)) {
if (!is_resource($this->outputStream)) {
$this->response = $response;
}

Expand Down Expand Up @@ -456,7 +456,7 @@ public function read()
*/
public function close()
{
if(is_resource($this->curl)) {
if (is_resource($this->curl)) {
curl_close($this->curl);
}
$this->curl = null;
Expand Down
8 changes: 4 additions & 4 deletions src/Client/Adapter/Proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function connect($host, $port = 80, $secure = false)

/* Url might require stream context even if proxy connection doesn't */
if ($secure) {
$this->config['sslusecontext'] = true;
$this->config['sslusecontext'] = true;
}

// Connect (a non-secure connection) to the proxy server
Expand Down Expand Up @@ -158,7 +158,7 @@ public function write($method, $uri, $http_ver = '1.1', $headers = array(), $bod
$request .= "$v\r\n";
}

if(is_resource($body)) {
if (is_resource($body)) {
$request .= "\r\n";
} else {
// Add the request body
Expand All @@ -171,7 +171,7 @@ public function write($method, $uri, $http_ver = '1.1', $headers = array(), $bod
}

if (is_resource($body)) {
if(stream_copy_to_stream($body, $this->socket) == 0) {
if (stream_copy_to_stream($body, $this->socket) == 0) {
throw new AdapterException\RuntimeException('Error writing request to server');
}
}
Expand Down Expand Up @@ -237,7 +237,7 @@ protected function connectHandshake($host, $port = 443, $http_ver = '1.1', array
);

$success = false;
foreach($modes as $mode) {
foreach ($modes as $mode) {
$success = stream_socket_enable_crypto($this->socket, true, $mode);
if ($success) break;
}
Expand Down
30 changes: 15 additions & 15 deletions src/Client/Adapter/Socket.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ public function setConfig($config = array())
*
* @return array
*/
public function getConfig()
{
return $this->config;
}
public function getConfig()
{
return $this->config;
}

/**
* Set the stream context for the TCP connection to the server
Expand Down Expand Up @@ -270,7 +270,7 @@ public function write($method, $uri, $http_ver = '1.1', $headers = array(), $bod
$request .= "$v\r\n";
}

if(is_resource($body)) {
if (is_resource($body)) {
$request .= "\r\n";
} else {
// Add the request body
Expand All @@ -282,8 +282,8 @@ public function write($method, $uri, $http_ver = '1.1', $headers = array(), $bod
throw new AdapterException\RuntimeException('Error writing request to server');
}

if(is_resource($body)) {
if(stream_copy_to_stream($body, $this->socket) == 0) {
if (is_resource($body)) {
if (stream_copy_to_stream($body, $this->socket) == 0) {
throw new AdapterException\RuntimeException('Error writing request to server');
}
}
Expand Down Expand Up @@ -368,8 +368,8 @@ public function read()
$current_pos = ftell($this->socket);
if ($current_pos >= $read_to) break;

if($this->out_stream) {
if(stream_copy_to_stream($this->socket, $this->out_stream, $read_to - $current_pos) == 0) {
if ($this->out_stream) {
if (stream_copy_to_stream($this->socket, $this->out_stream, $read_to - $current_pos) == 0) {
$this->_checkSocketReadTimeout();
break;
}
Expand All @@ -386,7 +386,7 @@ public function read()
$chunk .= @fgets($this->socket);
$this->_checkSocketReadTimeout();

if(!$this->out_stream) {
if (!$this->out_stream) {
$response .= $chunk;
}
} while ($chunksize > 0);
Expand Down Expand Up @@ -418,8 +418,8 @@ public function read()
$read_to > $current_pos;
$current_pos = ftell($this->socket)) {

if($this->out_stream) {
if(@stream_copy_to_stream($this->socket, $this->out_stream, $read_to - $current_pos) == 0) {
if ($this->out_stream) {
if (@stream_copy_to_stream($this->socket, $this->out_stream, $read_to - $current_pos) == 0) {
$this->_checkSocketReadTimeout();
break;
}
Expand All @@ -441,12 +441,12 @@ public function read()
} else {

do {
if($this->out_stream) {
if(@stream_copy_to_stream($this->socket, $this->out_stream) == 0) {
if ($this->out_stream) {
if (@stream_copy_to_stream($this->socket, $this->out_stream) == 0) {
$this->_checkSocketReadTimeout();
break;
}
} else {
} else {
$buff = @fread($this->socket, 8192);
if ($buff === false || strlen($buff) === 0) {
$this->_checkSocketReadTimeout();
Expand Down
2 changes: 1 addition & 1 deletion src/Client/Adapter/Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public function addResponse($response)
{
if ($response instanceof Response) {
$response = $response->toString();
}
}

$this->responses[] = $response;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Header/AbstractAccept.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ protected function addType($type, $priority = 1, $level = null)
'priority' => $priority,
'level' => (integer) $level
);
} else {
} else {
$this->prioritizedValues[] = array(
'type' => $type,
'priority' => $priority
Expand Down
2 changes: 1 addition & 1 deletion src/Header/Accept.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1
*/
class Accept extends AbstractAccept
{
{
protected $regexAddType = '#^([a-zA-Z+-]+|\*)/(\*|[a-zA-Z0-9+-]+)$#';

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Header/SetCookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public function getFieldValue()
}

$value = $this->getValue();
if (strpos($value,'"')!==false) {
if (strpos($value, '"')!==false) {
$value = '"'.urlencode(str_replace('"', '', $value)).'"';
} else {
$value = urlencode($value);
Expand Down
5 changes: 2 additions & 3 deletions src/PhpEnvironment/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,7 @@ public function setServer(ParametersDescription $server)
if (preg_match('|^([^:]+):([^:]+)$|', $this->headers()->get('host')->getFieldValue(), $match)) {
$uri->setHost($match[1]);
$uri->setPort($match[2]);
}
else {
} else {
$uri->setHost($this->headers()->get('host')->getFieldValue());
}
} elseif (isset($this->serverParams['SERVER_NAME'])) {
Expand Down Expand Up @@ -311,7 +310,7 @@ protected function detectBaseUrl()
}

// Directory portion of base path matches.
$baseDir = str_replace('\\','/', dirname($baseUrl));
$baseDir = str_replace('\\', '/', dirname($baseUrl));
if (0 === strpos($requestUri, $baseDir)) {
return $baseDir;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public static function fromString($string)
{
$lines = explode("\r\n", $string);
if (!is_array($lines) || count($lines)==1) {
$lines = explode("\n",$string);
$lines = explode("\n", $string);
}

$firstLine = array_shift($lines);
Expand Down
Loading

0 comments on commit a42a64f

Please sign in to comment.