From: Tim Düsterhus Date: Wed, 15 Jul 2020 10:06:32 +0000 (+0200) Subject: Set default user-agent for Guzzle X-Git-Tag: 5.3.0_Alpha_1~132^2~1 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=ef9eafba8d9b9a8525b3ed53370261453af0600a;p=GitHub%2FWoltLab%2FWCF.git Set default user-agent for Guzzle --- diff --git a/wcfsetup/install/files/lib/system/io/HttpFactory.class.php b/wcfsetup/install/files/lib/system/io/HttpFactory.class.php index 45df454296..b8c42e97e8 100644 --- a/wcfsetup/install/files/lib/system/io/HttpFactory.class.php +++ b/wcfsetup/install/files/lib/system/io/HttpFactory.class.php @@ -22,6 +22,17 @@ final class HttpFactory { */ private static $defaultClient; + /** + * Returns a RFC 7231#5.5.3 compatible user agent. + * + * @return string + */ + public static function getDefaultUserAgent() { + $version = preg_replace('/^(\d+\.\d+)\..*$/', '\\1', WCF_VERSION); + + return 'WoltLabSuite/'.$version; + } + /** * Returns a reference to the default HTTP client. * @@ -47,6 +58,9 @@ final class HttpFactory { public static function makeClient(array $options = []) { return new Client(array_merge([ 'proxy' => PROXY_SERVER_HTTP, + 'headers' => [ + 'user-agent' => self::getDefaultUserAgent(), + ] ], $options)); } }