Browse Source

Merge pull request #148 from provokateurin/fix/user-agent

Fix user agent
pull/149/head
Kate 2 years ago committed by GitHub
parent
commit
f90924c93e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      packages/dynamite/lib/src/openapi_builder.dart
  2. 8
      packages/neon/lib/src/models/account.dart
  3. 2
      packages/nextcloud/lib/src/client.dart
  4. 3
      packages/nextcloud/lib/src/nextcloud.openapi.dart

8
packages/dynamite/lib/src/openapi_builder.dart

@ -395,6 +395,12 @@ class OpenAPIBuilder implements Builder {
..type = refer('Map<String, String>?')
..named = true,
),
Parameter(
(final b) => b
..name = 'userAgent'
..type = refer('String?')
..named = true,
),
Parameter(
(final b) => b
..name = 'httpClient'
@ -427,7 +433,7 @@ class OpenAPIBuilder implements Builder {
},
''' : ''}
};
this.httpClient = httpClient ?? HttpClient();
this.httpClient = (httpClient ?? HttpClient())..userAgent = userAgent;
'''),
),
)

8
packages/neon/lib/src/models/account.dart

@ -7,7 +7,13 @@ import 'package:package_info_plus/package_info_plus.dart';
part 'account.g.dart';
String userAgent(final PackageInfo packageInfo) => 'Neon ${packageInfo.version}+${packageInfo.buildNumber}';
String userAgent(final PackageInfo packageInfo) {
var buildNumber = packageInfo.buildNumber;
if (buildNumber == '') {
buildNumber = '1';
}
return 'Neon ${packageInfo.version}+$buildNumber';
}
@JsonSerializable()
class Account {

2
packages/nextcloud/lib/src/client.dart

@ -16,9 +16,9 @@ class NextcloudClient extends Client {
'OCS-APIRequest': 'true',
'Accept': 'application/json',
'Accept-Language': language,
'User-Agent': userAgentOverride ?? appType.userAgent,
}..removeWhere((final _, final value) => value == null))
.cast<String, String>(),
userAgent: userAgentOverride ?? appType.userAgent,
authentication: username != null && password != null
? HttpBasicAuthentication(
username: username,

3
packages/nextcloud/lib/src/nextcloud.openapi.dart

@ -93,6 +93,7 @@ class Client {
Client(
this.baseURL, {
Map<String, String>? baseHeaders,
String? userAgent,
HttpClient? httpClient,
this.cookieJar,
this.authentication,
@ -105,7 +106,7 @@ class Client {
...authentication!.headers,
},
};
this.httpClient = httpClient ?? HttpClient();
this.httpClient = (httpClient ?? HttpClient())..userAgent = userAgent;
}
final String baseURL;

Loading…
Cancel
Save