8000 [HttpClient] fix using stream_copy_to_stream() with responses cast to… · grasmash/symfony@cf1404a · GitHub
[go: up one dir, main page]

Skip to content

Commit cf1404a

Browse files
[HttpClient] fix using stream_copy_to_stream() with responses cast to php streams
1 parent 3d1c59a commit cf1404a

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
< 9010 td data-grid-cell-id="diff-9376e4179e2a1c5e0eeaa3cf6226f0e5509ff79a5c8499825586eb7d61d5d3c4-65-67-0" data-selected="false" role="gridcell" style="background-color:var(--diffBlob-additionNum-bgColor, var(--diffBlob-addition-bgColor-num));text-align:center" tabindex="-1" valign="top" class="focusable-grid-cell diff-line-number position-relative left-side">
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