diff --git a/lib/api/core.dart b/lib/api/core.dart index b28da078b8..5762a526f3 100644 --- a/lib/api/core.dart +++ b/lib/api/core.dart @@ -80,6 +80,7 @@ class ApiConnection { assert(debugLog("${request.method} ${request.url}")); addAuth(request); + request.headers.addAll(userAgentHeader()); final http.StreamedResponse response; try { @@ -198,6 +199,13 @@ Map authHeader({required String email, required String apiKey}) }; } +// TODO(#453): Create real User-Agent string +Map userAgentHeader() { + return { + 'User-Agent': 'ZulipMobile/?.?.? (Android 14)', + }; +} + Map? encodeParameters(Map? params) { return params?.map((k, v) => MapEntry(k, v is RawParameter ? v.value : jsonEncode(v))); diff --git a/test/api/core_test.dart b/test/api/core_test.dart index c5883b386f..c3e9cbb735 100644 --- a/test/api/core_test.dart +++ b/test/api/core_test.dart @@ -23,7 +23,10 @@ void main() { check(connection.lastRequest!).isA() ..method.equals('GET') ..url.asString.equals('${eg.realmUrl.origin}$expectedRelativeUrl') - ..headers.deepEquals(authHeader(email: eg.selfAccount.email, apiKey: eg.selfAccount.apiKey)) + ..headers.deepEquals({ + ...authHeader(email: eg.selfAccount.email, apiKey: eg.selfAccount.apiKey), + ...userAgentHeader(), + }) ..body.equals(''); }); } @@ -53,6 +56,7 @@ void main() { ..url.asString.equals('${eg.realmUrl.origin}/api/v1/example/route') ..headers.deepEquals({ ...authHeader(email: eg.selfAccount.email, apiKey: eg.selfAccount.apiKey), + ...userAgentHeader(), if (expectContentType) 'content-type': 'application/x-www-form-urlencoded; charset=utf-8', }) @@ -83,7 +87,10 @@ void main() { check(connection.lastRequest!).isA() ..method.equals('POST') ..url.asString.equals('${eg.realmUrl.origin}/api/v1/example/route') - ..headers.deepEquals(authHeader(email: eg.selfAccount.email, apiKey: eg.selfAccount.apiKey)) + ..headers.deepEquals({ + ...authHeader(email: eg.selfAccount.email, apiKey: eg.selfAccount.apiKey), + ...userAgentHeader(), + }) ..fields.deepEquals({}) ..files.single.which(it() ..field.equals('file') @@ -115,6 +122,7 @@ void main() { ..url.asString.equals('${eg.realmUrl.origin}/api/v1/example/route') ..headers.deepEquals({ ...authHeader(email: eg.selfAccount.email, apiKey: eg.selfAccount.apiKey), + ...userAgentHeader(), if (expectContentType) 'content-type': 'application/x-www-form-urlencoded; charset=utf-8', })