diff --git a/src/ClientFactory.php b/src/ClientFactory.php index 8792bef..efb28ac 100644 --- a/src/ClientFactory.php +++ b/src/ClientFactory.php @@ -16,38 +16,9 @@ use FriendsOfHyperf\Jet\Contract\PackerInterface; use FriendsOfHyperf\Jet\Contract\PathGeneratorInterface; use FriendsOfHyperf\Jet\Contract\TransporterInterface; -use GuzzleHttp\ClientInterface; class ClientFactory { - /** - * User agent. - * @var string - */ - protected static $userAgent; - - /** - * Set user agent. - */ - public static function setUserAgent(string $userAgent): void - { - self::$userAgent = $userAgent; - } - - /** - * Get user agent. - */ - public static function getUserAgent(): string - { - return self::$userAgent ?: sprintf( - 'jet/%s php/%s guzzle/%s curl/%s', - Client::MAJOR_VERSION, - PHP_VERSION, - defined(ClientInterface::class . '::VERSION') ? constant(ClientInterface::class . '::VERSION') : constant(ClientInterface::class . '::MAJOR_VERSION'), - curl_version()['version'] - ); - } - /** * Create a client. * @param null|int|string|TransporterInterface $transporter transporter, protocol, timeout or null diff --git a/src/Support/UserAgent.php b/src/Support/UserAgent.php new file mode 100644 index 0000000..8313c2d --- /dev/null +++ b/src/Support/UserAgent.php @@ -0,0 +1,40 @@ + 'application/json', 'X-Real-Ip' => $_SERVER['SERVER_ADDR'] ?? '', 'X-Forwarded-For' => $_SERVER['REMOTE_ADDR'] ?? '', - 'User-Agent' => ClientFactory::getUserAgent(), + 'User-Agent' => UserAgent::get(), ], 'http_errors' => false, ]);