1
0
mirror of https://github.com/guzzle/guzzle.git synced 2025-02-24 10:03:27 +01:00

Use a LazyOpenStream instead of try_fopen r+

This commit is contained in:
Jonathan Eskew 2016-01-25 10:32:37 -08:00
parent 5741733ee5
commit 7377cff8fa
2 changed files with 16 additions and 1 deletions

View File

@ -138,7 +138,7 @@ class StreamHandler
: fopen('php://temp', 'r+');
return is_string($sink)
? new Psr7\Stream(Psr7\try_fopen($sink, 'r+'))
? new Psr7\LazyOpenStream($sink, 'w+')
: Psr7\stream_for($sink);
}

View File

@ -127,6 +127,21 @@ class StreamHandlerTest extends \PHPUnit_Framework_TestCase
unlink($tmpfname);
}
public function testDrainsResponseIntoSaveToBodyAtNonExistentPath()
{
$tmpfname = tempnam('/tmp', 'save_to_path');
unlink($tmpfname);
$this->queueRes();
$handler = new StreamHandler();
$request = new Request('GET', Server::$url);
$response = $handler($request, ['sink' => $tmpfname])->wait();
$body = $response->getBody();
$this->assertEquals($tmpfname, $body->getMetadata('uri'));
$this->assertEquals('hi', $body->read(2));
$body->close();
unlink($tmpfname);
}
public function testAutomaticallyDecompressGzip()
{
Server::flush();