Skip to content

Commit 01cb9d5

Browse files
authored
Return message body when stream buffer is empty (#5)
1 parent 08e2591 commit 01cb9d5

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "rtckit/sip",
33
"description": "Parser/Renderer for SIP protocol written in PHP",
4-
"version": "0.2.3",
4+
"version": "0.2.4",
55
"type": "library",
66
"keywords": [
77
"sip",

src/StreamParser.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ public function process(string $chunk, ?array &$messages): int
7979
$this->buffer = ltrim(substr($this->buffer, $this->message->contentLength->value));
8080
} else {
8181
/* We're all set! */
82+
$this->message->body = $this->buffer;
8283
$this->buffer = '';
8384
}
8485
} else {

tests/StreamParserTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,19 @@ public function testShouldParseVariousChunkSizes()
6060
fclose($fp);
6161
}
6262

63+
public function testShouldParseStreamedMessagesNoDifferentThanPDU()
64+
{
65+
$bytes = file_get_contents(__DIR__ . '/fixtures/rfc4475/wsinv.dat');
66+
67+
if ($this->parser->process($bytes, $messages) === StreamParser::SUCCESS) {
68+
/* Expect one message and one message only */
69+
$this->assertEquals(1, count($messages));
70+
71+
/* The streamed message to be parsed as if it was an individual PDU */
72+
$this->assertEquals(Message::parse($bytes), $messages[0]);
73+
}
74+
}
75+
6376
public function testFailureWithoutContentLength()
6477
{
6578
$bytes =

0 commit comments

Comments
 (0)