Skip to content

Commit 478425c

Browse files
committed
Merge branch '7.0' into 7.1
* 7.0: (39 commits) fix merge add missing return type-hints fix merge explicitly mark nullable parameters as nullable fix low deps tests [HttpKernel] Fix datacollector caster for reference object property [Serializer] Fixing PHP warning in the ObjectNormalizer with MaxDepth enabled bug #51578 [Cache] always select database for persistent redis connections [Security] Validate that CSRF token in form login is string similar to username/password [Serializer] Use explicit nullable type [validator] validated Dutch translation Improve dutch translations initialize the current time with midnight before modifying the date [Translation] Skip state=needs-translation entries only when source == target [HttpKernel] Ensure controllers are not lazy [Validator] Fill in trans-unit id 113: This URL does not contain a TLD. [Validator] added missing Polish translation for unit 113 [Validator] add missing lv translation fix tests [HttpClient] Let curl handle transfer encoding ...
2 parents 6b89def + 1cdf95d commit 478425c

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

CurlHttpClient.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,8 @@ public function request(string $method, string $url, array $options = []): Respo
250250

251251
if (isset($options['normalized_headers']['content-length'][0])) {
252252
$curlopts[\CURLOPT_INFILESIZE] = (int) substr($options['normalized_headers']['content-length'][0], \strlen('Content-Length: '));
253-
}
254-
if (!isset($options['normalized_headers']['transfer-encoding'])) {
255-
$curlopts[\CURLOPT_HTTPHEADER][] = 'Transfer-Encoding:'.(isset($curlopts[\CURLOPT_INFILESIZE]) ? '' : ' chunked');
253+
} elseif (!isset($options['normalized_headers']['transfer-encoding'])) {
254+
$curlopts[\CURLOPT_INFILESIZE] = -1;
256255
}
257256

258257
if ('POST' !== $method) {

EventSourceHttpClient.php

Lines 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

Lines changed: 13 additions & 7 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+
$rawData = <<<TXT
3338
event: builderror
3439
id: 46
3540
data: {"foo": "bar"}
@@ -58,6 +63,7 @@ public function testGetServerSentEvents()
5863
id: 60
5964
data
6065
TXT;
66+
$data = str_replace("\n", $sep, $rawData);
6167

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

8490
$expected = [
8591
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"),
92+
new ServerSentEvent(str_replace("\n", $sep, "event: builderror\nid: 46\ndata: {\"foo\": \"bar\"}\n\n")),
93+
new ServerSentEvent(str_replace("\n", $sep, "event: reload\nid: 47\ndata: {}\n\n")),
94+
new ServerSentEvent(str_replace("\n", $sep, "event: reload\nid: 48\ndata: {}\n\n")),
95+
new ServerSentEvent(str_replace("\n", $sep, "data: test\ndata:test\nid: 49\nevent: testEvent\n\n\n")),
96+
new ServerSentEvent(str_replace("\n", $sep, "id: 50\ndata: <tag>\ndata\ndata: <foo />\ndata\ndata: </tag>\n\n")),
9197
];
9298
$i = 0;
9399

0 commit comments

Comments
 (0)