10000 bug #40587 [HttpClient] fix using stream_copy_to_stream() with respon… · grasmash/symfony@9889c49 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9889c49

Browse files
committed
bug symfony#40587 [HttpClient] fix using stream_copy_to_stream() with responses cast to php streams (nicolas-grekas)
This PR was merged into the 4.4 branch. Discussion ---------- [HttpClient] fix using stream_copy_to_stream() with responses cast to php streams | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix symfony#40574 | License | MIT | Doc PR | - Commits ------- cf1404a [HttpClient] fix using stream_copy_to_stream() with responses cast to php streams
2 parents 0d99f93 + cf1404a commit 9889c49

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/Symfony/Component/HttpClient/Response/StreamWrapper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ public function stream_stat(): array
281281
'uid' => 0,
282282
'gid' => 0,
283283
'rdev' => 0,
284-
'size' => (int) ($headers['content-length'][0] ?? 0),
284+
'size' => (int) ($headers['content-length'][0] ?? -1),
285285
'atime' => 0,
286286
'mtime' => strtotime($headers['last-modified'][0] ?? '') ?: 0,
287287
'ctime' => 0,

src/Symfony/Component/HttpClient/Tests/HttpClientTestCase.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,19 @@ public function testToStream()
6363
$this->assertTrue(feof($stream));
6464
}
6565

66+
public function testStreamCopyToStream()
67+
{
68+
$client = $this->getHttpClient(__FUNCTION__);
69+
$response = $client->request('GET', 'http://localhost:8057');
70+
$h = fopen('php://temp', 'w+');
71+
stream_copy_to_stream($response->toStream(), $h);
72+
73+
$this->assertTrue(rewind($h));
74+
$this->assertSame("{\n \"SER", fread($h, 10));
75+
$this->assertSame('VER_PROTOCOL', fread($h, 12));
76+
$this->assertFalse(feof($h));
77+
}
78+
6679
public function testToStream404()
6780
{
6881
$client = $this->getHttpClient(__FUNCTION__);

0 commit comments

Comments
 (0)
0