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

Commit bc1710e

Browse filesBrowse files
committed
bug #54242 [HttpClient] [EventSourceHttpClient] Fix consuming SSEs with \r\n separator (fancyweb)
This PR was merged into the 5.4 branch. Discussion ---------- [HttpClient] [EventSourceHttpClient] Fix consuming SSEs with \r\n separator | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | - | License | MIT `\r\n` separator never worked because it splits on every line because of `[\r\n]`. Commits ------- 2c095d8296 [HttpClient][EventSourceHttpClient] Fix consuming SSEs with \r\n separator
2 parents 2a29219 + 0b05c4f commit bc1710e
Copy full SHA for bc1710e

File tree

Expand file treeCollapse file tree

2 files changed

+14
-9
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+14
-9
lines changed

‎EventSourceHttpClient.php

Copy file name to clipboardExpand all lines: EventSourceHttpClient.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public function request(string $method, string $url, array $options = []): Respo
121121
return;
122122
}
123123

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

127127
if ($chunk->isLast()) {

‎Tests/EventSourceHttpClientTest.php

Copy file name to clipboardExpand all lines: Tests/EventSourceHttpClientTest.php
+13-8Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,14 @@
2727
*/
2828
class EventSourceHttpClientTest extends TestCase
2929
{
30-
public function testGetServerSentEvents()
30+
/**
31+
* @testWith ["\n"]
32+
* ["\r"]
33+
* ["\r\n"]
34+
*/
35+
public function testGetServerSentEvents(string $sep)
3136
{
32-
$data = <<<TXT
37+
$data = str_replace("\n", $sep, <<<TXT
3338
event: builderror
3439
id: 46
3540
data: {"foo": "bar"}
@@ -57,7 +62,7 @@ public function testGetServerSentEvents()
5762
5863
id: 60
5964
data
60-
TXT;
65+
TXT);
6166

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

8489
$expected = [
8590
new FirstChunk(),
86-
new ServerSentEvent("event: builderror\nid: 46\ndata: {\"foo\": \"bar\"}\n\n"),
87-
new ServerSentEvent("event: reload\nid: 47\ndata: {}\n\n"),
88-
new ServerSentEvent("event: reload\nid: 48\ndata: {}\n\n"),
89-
new ServerSentEvent("data: test\ndata:test\nid: 49\nevent: testEvent\n\n\n"),
90-
new ServerSentEvent("id: 50\ndata: <tag>\ndata\ndata: <foo />\ndata\ndata: </tag>\n\n"),
91+
new ServerSentEvent(str_replace("\n", $sep, "event: builderror\nid: 46\ndata: {\"foo\": \"bar\"}\n\n")),
92+
new ServerSentEvent(str_replace("\n", $sep, "event: reload\nid: 47\ndata: {}\n\n")),
93+
new ServerSentEvent(str_replace("\n", $sep, "event: reload\nid: 48\ndata: {}\n\n")),
94+
new ServerSentEvent(str_replace("\n", $sep, "data: test\ndata:test\nid: 49\nevent: testEvent\n\n\n")),
95+
new ServerSentEvent(str_replace("\n", $sep, "id: 50\ndata: <tag>\ndata\ndata: <foo />\ndata\ndata: </tag>\n\n")),
9196
];
9297
$i = 0;
9398

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.