Issue DEVEX-2062: PHP Stream Wrapper not working.

The issue had to do with a failure to communicate EOF from server
to client. I resolved this by doing chunked reads.
This commit is contained in:
Technosophos 2012-05-30 17:27:21 -05:00
parent 30d6aa4568
commit 9fb8525dc9
2 changed files with 22 additions and 2 deletions

View File

@ -166,15 +166,16 @@ class Response {
$out = '';
// This should always be set... but...
/*
if (isset($this->metadata['unread_bytes'])) {
$bytes = (int) $this->metadata['unread_bytes'];
if ($bytes == 0 && $this->header('Content-Length', 0) > 0) {
fwrite(STDOUT, print_r($this->metadata, TRUE));
throw new \HPCloud\Exception(sprintf(
'Content length %d doesn\'t match byte count %d.',
$this->header('Content-Length', 0),
$bytes
));
throw new \Exception(print_r($this->metadata, TRUE));
}
$out = fread($this->handle, $bytes);
//$out = stream_get_contents($this->handle);
@ -186,6 +187,25 @@ class Response {
$out .= fread($this->handle, 8192);
}
}
*/
// XXX: The addition of the Content-Length check is a workaround
// for an issue with using PHP Stream Wrappers to communicate with
// Identity Service. Apparently, the remote does not provide
// an EOF marker, and PHP is too dumb to truncate at Content-Length,
// so we have to do it manually.
$max = $this->header('Content-Length', NULL);
if (isset($this->metadata['unread_bytes']) && isset($max)) {
while (!feof($this->handle) && strlen($out) < $max) {
$out .= fread($this->handle, 8192);
}
}
else {
while (!feof($this->handle)) {
$out .= fread($this->handle, 8192);
}
}
// Should we close or rewind?
// Cannot rewind PHP HTTP streams.

View File

@ -32,7 +32,7 @@ require_once 'test/TestCase.php';
use \HPCloud\Transport;
use \HPCloud\Transport\CURLTransport;
class ObjectTest extends \HPCloud\Tests\TestCase {
class CURLTransportTest extends \HPCloud\Tests\TestCase {
public static function tearDownAfterClass() {
$transport = NULL;