diff --git a/lib/src/model/common/http.dart b/lib/src/model/common/http.dart index 778c477893..a3195b0a35 100644 --- a/lib/src/model/common/http.dart +++ b/lib/src/model/common/http.dart @@ -102,6 +102,25 @@ String userAgent(UserAgentRef ref) { ); } +/// Creates a user-agent string with the app version, build number, and device info and possibly the user ID if a user is logged in. +String makeUserAgent( + PackageInfo info, + BaseDeviceInfo deviceInfo, + String sri, + LightUser? user, +) { + final base = + 'Lichess Mobile/${info.version} as:${user?.id ?? 'anon'} sri:$sri'; + + if (deviceInfo is AndroidDeviceInfo) { + return '$base os:Android/${deviceInfo.version.release} dev:${deviceInfo.model}'; + } else if (deviceInfo is IosDeviceInfo) { + return '$base os:iOS/${deviceInfo.systemVersion} dev:${deviceInfo.model}'; + } + + return base; +} + /// Http client that sets the Authorization header when a token has been stored. /// /// Also sets the user-agent header with the app version, build number, and device info. @@ -456,21 +475,3 @@ extension ClientAutoDisposeRefExtension on AutoDisposeRef { } } } - -String makeUserAgent( - PackageInfo info, - BaseDeviceInfo deviceInfo, - String sri, - LightUser? user, -) { - final base = - 'Lichess Mobile/${info.version} as:${user?.id ?? 'anon'} sri:$sri'; - - if (deviceInfo is AndroidDeviceInfo) { - return '$base os:Android/${deviceInfo.version.release} dev:${deviceInfo.model}'; - } else if (deviceInfo is IosDeviceInfo) { - return '$base os:iOS/${deviceInfo.systemVersion} dev:${deviceInfo.model}'; - } - - return base; -}