Add ImageProxyAction::getHttpClient()
authorTim Düsterhus <duesterhus@woltlab.com>
Fri, 5 Mar 2021 12:55:26 +0000 (13:55 +0100)
committerTim Düsterhus <duesterhus@woltlab.com>
Fri, 5 Mar 2021 12:55:45 +0000 (13:55 +0100)
wcfsetup/install/files/lib/action/ImageProxyAction.class.php

index cf00837f7b1b72d2dc32747ac8941e2bf3280f29..b890429e0976c9d5cac34eb17f050ec143d20b2f 100644 (file)
@@ -2,6 +2,7 @@
 
 namespace wcf\action;
 
+use GuzzleHttp\ClientInterface;
 use GuzzleHttp\Exception\TransferException;
 use GuzzleHttp\Psr7\Request;
 use GuzzleHttp\RequestOptions;
@@ -55,6 +56,18 @@ class ImageProxyAction extends AbstractAction
         }
     }
 
+    /**
+     * Returns the HTTP Client used for downloading images.
+     * @since 5.4
+     */
+    private function getHttpClient(): ClientInterface
+    {
+        return HttpFactory::makeClient([
+            RequestOptions::TIMEOUT => 10,
+            RequestOptions::STREAM => true,
+        ]);
+    }
+
     /**
      * @inheritDoc
      */
@@ -107,15 +120,11 @@ class ImageProxyAction extends AbstractAction
                     $file = null;
                     $response = null;
                     try {
-                        $client = HttpFactory::makeClient([
-                            RequestOptions::TIMEOUT => 10,
-                            RequestOptions::STREAM => true,
-                        ]);
                         $request = new Request('GET', $url, [
                             'via' => '1.1 wsc',
                             'accept' => 'image/*',
                         ]);
-                        $response = $client->send($request);
+                        $response = $this->getHttpClient()->send($request);
 
                         $file = new File($tmp);
                         while (!$response->getBody()->eof()) {