Skip to content

Commit

Permalink
Merge pull request #910 from Yurunsoft/fix-sse
Browse files Browse the repository at this point in the history
Fix the SSE response data format
  • Loading branch information
walkor authored Apr 28, 2023
2 parents 4462291 + f3eec6f commit 977822c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions src/Protocols/Http/ServerSentEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ public function __toString()
if (isset($data['event'])) {
$buffer .= "event: {$data['event']}\n";
}
if (isset($data['data'])) {
$buffer .= 'data: ' . str_replace("\n", "\ndata: ", $data['data']) . "\n\n";
}
if (isset($data['id'])) {
$buffer .= "id: {$data['id']}\n";
}
if (isset($data['retry'])) {
$buffer .= "retry: {$data['retry']}\n";
}
return $buffer;
if (isset($data['data'])) {
$buffer .= 'data: ' . str_replace("\n", "\ndata: ", $data['data']) . "\n";
}
return $buffer . "\n";
}
}
}
4 changes: 2 additions & 2 deletions tests/Unit/Protocols/Http/ServerSentEventsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
'retry' => 5000,
];
$sse = new ServerSentEvents($data);
$expected = "event: {$data['event']}\ndata: {$data['data']}\n\nid: {$data['id']}\nretry: {$data['retry']}\n";
$expected = "event: {$data['event']}\nid: {$data['id']}\nretry: {$data['retry']}\ndata: {$data['data']}\n\n";
expect((string)$sse)->toBe($expected);
});
});

0 comments on commit 977822c

Please sign in to comment.