From ce163806c468763f6e3b04e4bf7318c6f8035737 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Mon, 24 Aug 2020 10:46:36 +0200 Subject: [PATCH] Fix Guzzle following redirects with a custom temporary sink MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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. --- wcfsetup/install/files/lib/system/style/FontManager.class.php | 2 +- wcfsetup/install/files/lib/util/HTTPRequest.class.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/wcfsetup/install/files/lib/system/style/FontManager.class.php b/wcfsetup/install/files/lib/system/style/FontManager.class.php index bfbe2ff589..d9bbd95b79 100644 --- a/wcfsetup/install/files/lib/system/style/FontManager.class.php +++ b/wcfsetup/install/files/lib/system/style/FontManager.class.php @@ -88,7 +88,7 @@ class FontManager extends SingletonFactory { $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); diff --git a/wcfsetup/install/files/lib/util/HTTPRequest.class.php b/wcfsetup/install/files/lib/util/HTTPRequest.class.php index 808f39ce77..e0eb6a2224 100644 --- a/wcfsetup/install/files/lib/util/HTTPRequest.class.php +++ b/wcfsetup/install/files/lib/util/HTTPRequest.class.php @@ -192,7 +192,7 @@ final class HTTPRequest { 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) { -- 2.20.1