-
Notifications
You must be signed in to change notification settings - Fork 310
Send hard-coded User-Agent in requests #450
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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<String, String> authHeader({required String email, required String apiKey}) | |
}; | ||
} | ||
|
||
// TODO(#453): Create real User-Agent string | ||
Map<String, String> userAgentHeader() { | ||
return { | ||
'User-Agent': 'ZulipMobile/?.?.? (Android 14)', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's work in something here to make clear this is actually the Flutter app, not the RN app. E.g., saying "ZulipFlutter". Tim suggests at #453 (comment) that it's enough for "ZulipMobile" to appear somewhere in the value, not necessarily at the start. Can we add something like "(like ZulipMobile)" at the end instead, and put "ZulipFlutter" at the start? Or if we do need it at the start, in the venerable tradition of every modern browser claiming to be Mozilla 5.0: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tested with live server and dug through https://github.com/zulip/zulip/blob/main/zerver/lib/user_agent.py . The User-Agent is parsed with this: pattern = re.compile(
"""^ (?P<name> [^/ ]* [^0-9/(]* )
(/ (?P<version> [^/ ]* ))?
([ /] .*)?
$""",
re.X,
) and the whitelist from https://github.com/zulip/zulip/blob/main/zerver/models/clients.py is: sending_client
in (
"zulipandroid",
"zulipios",
"zulipdesktop",
"zulipmobile",
"zulipelectron",
"zulipterminal",
"snipe",
"website",
"ios",
"android",
)
or "desktop app" in sending_client
# Since the vast majority of messages are sent by humans
# in Zulip, treat test suite messages as such.
or (sending_client == "test suite" and settings.TEST_SUITE) To trigger a match we could not start the string with "ZulipFlutter". I think given the options we should present as "ZulipMobile" and stick on a "(like ZulipMobile)" at the end. We could possibly start with "ZulipFlutter; like desktop app" or "ZulipFlutter(like desktop app)" (but NOT "ZulipFlutter (like desktop app)") but I don't like these options. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, let's do a string like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In fact, better yet: once we do have the version number, it'll be from a different sequence from the zulip-mobile version numbers anyway. So rather than saying "ZulipMobile/1.2.3", we can let the version number remain absent at that spot and instead say a string like |
||
}; | ||
} | ||
|
||
Map<String, String>? encodeParameters(Map<String, dynamic>? params) { | ||
return params?.map((k, v) => | ||
MapEntry(k, v is RawParameter ? v.value : jsonEncode(v))); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
import 'dart:ui'; | ||
|
||
import 'package:flutter/material.dart'; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
import 'dart:ui'; | ||
|
||
import 'package:checks/checks.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Saying "Android 14" means making up bogus, untruthful, data — we might be on some other Android version, or on iOS — so let's avoid that.
By contrast saying "?.?.?" for the version number is fine, at least as a stopgap, because it's honest about what this code doesn't know.