Merge branch 'develop' into feature/DBaaS
This commit is contained in:
commit
c50b708880
@ -84,6 +84,10 @@ class PHPStreamTransport implements Transporter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$metadata = stream_get_meta_data($res);
|
$metadata = stream_get_meta_data($res);
|
||||||
|
if (\HPCloud\Bootstrap::hasConfig('transport.debug')) {
|
||||||
|
fwrite(STDOUT, implode(PHP_EOL, $metadata['wrapper_data']));
|
||||||
|
fprintf(STDOUT, "\nWaiting to read %d bytes.\n", $metadata['unread_bytes']);
|
||||||
|
}
|
||||||
|
|
||||||
$response = new Response($res, $metadata);
|
$response = new Response($res, $metadata);
|
||||||
|
|
||||||
@ -217,7 +221,6 @@ class PHPStreamTransport implements Transporter {
|
|||||||
* stream context. This builds the context.
|
* stream context. This builds the context.
|
||||||
*/
|
*/
|
||||||
protected function buildStreamContext($method, $headers, $body) {
|
protected function buildStreamContext($method, $headers, $body) {
|
||||||
|
|
||||||
// Construct the stream options.
|
// Construct the stream options.
|
||||||
$config = array(
|
$config = array(
|
||||||
'http' => array(
|
'http' => array(
|
||||||
@ -239,7 +242,12 @@ class PHPStreamTransport implements Transporter {
|
|||||||
// Set the params. (Currently there is only one.)
|
// Set the params. (Currently there is only one.)
|
||||||
$params = array();
|
$params = array();
|
||||||
if (!empty($this->notificationCallback)) {
|
if (!empty($this->notificationCallback)) {
|
||||||
$params['notification_callback'] = $this->notificationCallback;
|
$params['notification'] = $this->notificationCallback;
|
||||||
|
}
|
||||||
|
// Enable debugging:
|
||||||
|
elseif (\HPCloud\Bootstrap::hasConfig('transport.debug')) {
|
||||||
|
fwrite(STDOUT, "Sending debug messages to STDOUT\n");
|
||||||
|
$params['notification'] = array($this, 'printNotifications');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build the context.
|
// Build the context.
|
||||||
@ -248,4 +256,41 @@ class PHPStreamTransport implements Transporter {
|
|||||||
return $context;
|
return $context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function printNotifications($code, $severity, $msg, $msgcode, $bytes, $len) {
|
||||||
|
static $filesize = 'Unknown';
|
||||||
|
|
||||||
|
switch ($code) {
|
||||||
|
case STREAM_NOTIFY_RESOLVE:
|
||||||
|
fprintf(STDOUT, "Resolved. %s\n", $msg);
|
||||||
|
break;
|
||||||
|
case STREAM_NOTIFY_FAILURE:
|
||||||
|
fprintf(STDOUT, "socket-level failure: %s\n", $msg);
|
||||||
|
break;
|
||||||
|
case STREAM_NOTIFY_COMPLETED:
|
||||||
|
fprintf(STDOUT, "Transaction complete. %s\n", $msg);
|
||||||
|
break;
|
||||||
|
//case STREAM_NOTIFY_REDIRECT:
|
||||||
|
// fprintf(STDOUT, "Redirect... %s\n", $msg);
|
||||||
|
// break;
|
||||||
|
case STREAM_NOTIFY_CONNECT:
|
||||||
|
fprintf(STDOUT, "Connect... %s\n", $msg);
|
||||||
|
break;
|
||||||
|
case STREAM_NOTIFY_FILE_SIZE_IS:
|
||||||
|
fprintf(STDOUT, "Content-length: %d\n", $len);
|
||||||
|
$filesize = $len;
|
||||||
|
break;
|
||||||
|
case STREAM_NOTIFY_MIME_TYPE_IS:
|
||||||
|
fprintf(STDOUT, "Content-Type: %s\n", $msg);
|
||||||
|
break;
|
||||||
|
case STREAM_NOTIFY_PROGRESS:
|
||||||
|
fwrite(STDOUT, $msg . PHP_EOL);
|
||||||
|
fprintf(STDOUT, "%d bytes of %s\n", $bytes, $filesize);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
fprintf(STDOUT, "Code: %d, Message: %s\n", $code, $msg);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -167,28 +167,24 @@ class Response {
|
|||||||
public function content() {
|
public function content() {
|
||||||
$out = '';
|
$out = '';
|
||||||
|
|
||||||
// This should always be set... but...
|
// XXX: The addition of the Content-Length check is a workaround
|
||||||
if (isset($this->metadata['unread_bytes'])) {
|
// for an issue with using PHP Stream Wrappers to communicate with
|
||||||
$bytes = (int) $this->metadata['unread_bytes'];
|
// Identity Service. Apparently, the remote does not provide
|
||||||
if ($bytes == 0 && $this->header('Content-Length', 0) > 0) {
|
// an EOF marker, and PHP is too dumb to truncate at Content-Length,
|
||||||
throw new \HPCloud\Exception(sprintf(
|
// so we have to do it manually.
|
||||||
'Content length %d doesn\'t match byte count %d.',
|
$max = $this->header('Content-Length', NULL);
|
||||||
$this->header('Content-Length', 0),
|
if (isset($this->metadata['unread_bytes']) && isset($max)) {
|
||||||
$bytes
|
while (!feof($this->handle) && strlen($out) < $max) {
|
||||||
));
|
$out .= fread($this->handle, 8192);
|
||||||
throw new \Exception(print_r($this->metadata, TRUE));
|
|
||||||
}
|
}
|
||||||
$out = fread($this->handle, $bytes);
|
|
||||||
//$out = stream_get_contents($this->handle);
|
|
||||||
}
|
}
|
||||||
// XXX: In cases of large files, isn't this the safer default?
|
|
||||||
else {
|
else {
|
||||||
$out = '';
|
|
||||||
while (!feof($this->handle)) {
|
while (!feof($this->handle)) {
|
||||||
$out .= fread($this->handle, 8192);
|
$out .= fread($this->handle, 8192);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Should we close or rewind?
|
// Should we close or rewind?
|
||||||
// Cannot rewind PHP HTTP streams.
|
// Cannot rewind PHP HTTP streams.
|
||||||
fclose($this->handle);
|
fclose($this->handle);
|
||||||
|
@ -32,7 +32,7 @@ require_once 'test/TestCase.php';
|
|||||||
use \HPCloud\Transport;
|
use \HPCloud\Transport;
|
||||||
use \HPCloud\Transport\CURLTransport;
|
use \HPCloud\Transport\CURLTransport;
|
||||||
|
|
||||||
class ObjectTest extends \HPCloud\Tests\TestCase {
|
class CURLTransportTest extends \HPCloud\Tests\TestCase {
|
||||||
|
|
||||||
public static function tearDownAfterClass() {
|
public static function tearDownAfterClass() {
|
||||||
$transport = NULL;
|
$transport = NULL;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user