Set default user-agent for Guzzle
authorTim Düsterhus <duesterhus@woltlab.com>
Wed, 15 Jul 2020 10:06:32 +0000 (12:06 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Wed, 15 Jul 2020 10:06:32 +0000 (12:06 +0200)
wcfsetup/install/files/lib/system/io/HttpFactory.class.php

index 45df454296435f70c5578a76982ef3fec9f14a6b..b8c42e97e8035bfca19f7cf463131cab2eff0bcf 100644 (file)
@@ -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));
        }
 }