Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[HttpClient] [EventSourceHttpClient] Fix consuming SSEs with \r\n separator #54242

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 5, 2024
Merged
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
2 changes: 1 addition & 1 deletion 2 src/Symfony/Component/HttpClient/EventSourceHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function request(string $method, string $url, array $options = []): Respo
return;
}

$rx = '/((?:\r\n|[\r\n]){2,})/';
$rx = '/((?:\r\n){2,}|\r{2,}|\n{2,})/';
$content = $state->buffer.$chunk->getContent();

if ($chunk->isLast()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,14 @@
*/
class EventSourceHttpClientTest extends TestCase
{
public function testGetServerSentEvents()
/**
* @testWith ["\n"]
* ["\r"]
* ["\r\n"]
*/
public function testGetServerSentEvents(string $sep)
{
$data = <<<TXT
$data = str_replace("\n", $sep, <<<TXT
event: builderror
id: 46
data: {"foo": "bar"}
Expand Down Expand Up @@ -57,7 +62,7 @@ public function testGetServerSentEvents()

id: 60
data
TXT;
TXT);

$chunk = new DataChunk(0, $data);
$response = new MockResponse('', ['canceled' => false, 'http_method' => 'GET', 'url' => 'http://localhost:8080/events', 'response_headers' => ['content-type: text/event-stream']]);
Expand All @@ -83,11 +88,11 @@ public function testGetServerSentEvents()

$expected = [
new FirstChunk(),
new ServerSentEvent("event: builderror\nid: 46\ndata: {\"foo\": \"bar\"}\n\n"),
new ServerSentEvent("event: reload\nid: 47\ndata: {}\n\n"),
new ServerSentEvent("event: reload\nid: 48\ndata: {}\n\n"),
new ServerSentEvent("data: test\ndata:test\nid: 49\nevent: testEvent\n\n\n"),
new ServerSentEvent("id: 50\ndata: <tag>\ndata\ndata: <foo />\ndata\ndata: </tag>\n\n"),
new ServerSentEvent(str_replace("\n", $sep, "event: builderror\nid: 46\ndata: {\"foo\": \"bar\"}\n\n")),
new ServerSentEvent(str_replace("\n", $sep, "event: reload\nid: 47\ndata: {}\n\n")),
new ServerSentEvent(str_replace("\n", $sep, "event: reload\nid: 48\ndata: {}\n\n")),
new ServerSentEvent(str_replace("\n", $sep, "data: test\ndata:test\nid: 49\nevent: testEvent\n\n\n")),
new ServerSentEvent(str_replace("\n", $sep, "id: 50\ndata: <tag>\ndata\ndata: <foo />\ndata\ndata: </tag>\n\n")),
];
$i = 0;

Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.