Skip to content

Commit

Permalink
send user agent
Browse files Browse the repository at this point in the history
  • Loading branch information
sirpengi committed Dec 13, 2023
1 parent 4a6c46b commit c25b01c
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions lib/api/core.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import 'dart:convert';
import 'dart:io';

import 'package:device_info_plus/device_info_plus.dart';
import 'package:http/http.dart' as http;
import 'package:package_info_plus/package_info_plus.dart';

import '../log.dart';
import '../model/localizations.dart';
Expand Down Expand Up @@ -69,6 +71,28 @@ class ApiConnection {
}
}

Future<void> addUserAgent(http.BaseRequest request) async {
final packageInfo = await PackageInfo.fromPlatform();
final deviceInfoPlugin = DeviceInfoPlugin();
final String applicationVersion = packageInfo.version;
final String systemName;
final String systemVersion;
if (Platform.isIOS) {
final deviceInfo = await deviceInfoPlugin.iosInfo;
systemName = deviceInfo.systemName;
systemVersion = deviceInfo.systemVersion;
} else if (Platform.isAndroid) {
final deviceInfo = await deviceInfoPlugin.androidInfo;
systemName = "Android";
systemVersion = deviceInfo.version.release;
} else {
systemName = "Desktop";
systemVersion = "?";
}
print('ZulipMobile/$applicationVersion ($systemName $systemVersion)');
request.headers['User-Agent'] = 'ZulipMobile/$applicationVersion ($systemName $systemVersion)';
}

final http.Client _client;

bool _isOpen = true;
Expand All @@ -80,6 +104,7 @@ class ApiConnection {
assert(debugLog("${request.method} ${request.url}"));

addAuth(request);
await addUserAgent(request);

final http.StreamedResponse response;
try {
Expand Down

0 comments on commit c25b01c

Please sign in to comment.