When following redirects Guzzle copies over the request options for the next
iteration internally, including the bare `resource` that was passed to it.
This bare resource will then be wrapped into the Stream wrapper. This stream
wrapper explicitely calls `close()` for the underlying resource when it is
being closed.
The created Streams for the subrequests will be closed before the `send`
function returns, thus ultimately closing the resource for the “parent”
request.
Fix this issue by passing a Stream, instead of a bare resource. This one
will be passed along as-is.
Fixes #3529.
$response = $this->http->send(new Request('GET', $family.'/'.$filename), [
// https://github.com/guzzle/guzzle/issues/2735
- 'sink' => fopen("php://temp", "w+"),
+ 'sink' => \GuzzleHttp\Psr7\stream_for(fopen("php://temp", "w+")),
]);
$file = new AtomicWriter($familyDirectory.'/'.$filename);
try {
$this->response = $client->send($request, [
// https://github.com/guzzle/guzzle/issues/2735
- 'sink' => fopen("php://temp", "w+"),
+ 'sink' => \GuzzleHttp\Psr7\stream_for(fopen("php://temp", "w+")),
]);
}
catch (TooManyRedirectsException $e) {