Skip to content

Commit 911177e

Browse files
[HttpClient] fix using stream_copy_to_stream() with responses cast to php streams
1 parent c579254 commit 911177e

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

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,

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)