Add HttpFactory::makeClientWithTimeout()
authorTim Düsterhus <duesterhus@woltlab.com>
Thu, 11 Feb 2021 14:40:43 +0000 (15:40 +0100)
committerTim Düsterhus <duesterhus@woltlab.com>
Thu, 11 Feb 2021 14:41:11 +0000 (15:41 +0100)
wcfsetup/install/files/lib/system/io/HttpFactory.class.php

index a2da764c99687cc63b037173af0b7f5072dc66c3..7e35ff34059a60a42ea5611d5ebd7dfabf13e2e7 100644 (file)
@@ -46,6 +46,20 @@ final class HttpFactory
         return self::$defaultClient;
     }
 
+    /**
+     * Creates a new HTTP client with the given $timeout as the maximum
+     * total transfer duration.
+     *
+     * @since 5.4
+     * @see HttpFactory::makeClient()
+     */
+    public static function makeClientWithTimeout(float $timeout): ClientInterface
+    {
+        return static::makeClient([
+            RequestOptions::TIMEOUT => $timeout,
+        ]);
+    }
+
     /**
      * Creates a new HTTP client.
      *