Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changes/nextrelease/fix-eventstream-final-event-eof.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"type": "bugfix",
"category": "",
"description": "Fixed an issue in NonSeekableStreamDecodingEventStreamIterator where the final event was dropped when reading it reached the end of the stream."
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ public function rewind()
public function next()
{
$this->tempBuffer[] = $this->stream->read(1);
if ($this->valid()) {
if ($this->stream->eof()) {
$this->currentEvent = null;
} else {
$this->key++;
$this->currentEvent = $this->parseEvent();
}
Expand All @@ -107,6 +109,6 @@ public function next()
#[\ReturnTypeWillChange]
public function valid()
{
return !$this->stream->eof();
return $this->currentEvent !== null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Aws\Test\Api\Parser;

use Aws\Api\Parser\NonSeekableStreamDecodingEventStreamIterator;
use GuzzleHttp\Psr7\BufferStream;
use GuzzleHttp\Psr7\NoSeekStream;
use GuzzleHttp\Psr7\StreamDecoratorTrait;
use GuzzleHttp\Psr7\Utils;
Expand Down Expand Up @@ -76,6 +77,23 @@ public function testValidReturnsTrueOnEOF()
$this->assertFalse($iterator->valid());
}

public function testValidReturnsTrueWhenFinalEventReachesEOF()
{
$encodedEvent = <<<EOF
AAAAhQAAAExjTu0wDTptZXNzYWdlLXR5cGUHAAVldmVudAs6ZXZlbnQtdHlwZQcABnBlcnNvbg06Y29udGVudC10eXBlBwAQYXBwbGljYXRpb24vanNvbnsibmFtZSI6ImZvbyIsImxhc3ROYW1lIjo
iZnV6eiIsImFnZSI6Mjh9+hfixw==
EOF;
$stream = new BufferStream();
$stream->write(base64_decode($encodedEvent));
$iterator = new NonSeekableStreamDecodingEventStreamIterator($stream);
$iterator->rewind();
$this->assertTrue($stream->eof());
$this->assertTrue($iterator->valid());
$this->assertSame('person', $iterator->current()['headers'][':event-type']);
$iterator->next();
$this->assertFalse($iterator->valid());
}

#[DataProvider('readAndHashBytesHandlesPartialReadsProvider')]
public function testReadAndHashBytesHandlesPartialReads(
string $eventName,
Expand Down