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:
parent
5741733ee5
commit
7377cff8fa
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user