Skip to content

Commit

Permalink
Comment method
Browse files Browse the repository at this point in the history
  • Loading branch information
veloce committed Feb 21, 2024
1 parent 568dba5 commit 46ed440
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions lib/src/model/common/http.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -456,21 +475,3 @@ extension ClientAutoDisposeRefExtension<T> on AutoDisposeRef<T> {
}
}
}

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;
}

0 comments on commit 46ed440

Please sign in to comment.