From 63bb2c8fcb71a9d5c71b85244dba3539b2b681fc Mon Sep 17 00:00:00 2001 From: jld3103 Date: Thu, 8 Dec 2022 14:13:16 +0100 Subject: [PATCH 1/2] dynamite,nextcloud: Fix setting user agent --- packages/dynamite/lib/src/openapi_builder.dart | 8 +++++++- packages/nextcloud/lib/src/client.dart | 2 +- packages/nextcloud/lib/src/nextcloud.openapi.dart | 3 ++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/dynamite/lib/src/openapi_builder.dart b/packages/dynamite/lib/src/openapi_builder.dart index ed26cdce..4cd6efe1 100644 --- a/packages/dynamite/lib/src/openapi_builder.dart +++ b/packages/dynamite/lib/src/openapi_builder.dart @@ -395,6 +395,12 @@ class OpenAPIBuilder implements Builder { ..type = refer('Map?') ..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; '''), ), ) diff --git a/packages/nextcloud/lib/src/client.dart b/packages/nextcloud/lib/src/client.dart index 803bd6bd..4d924364 100644 --- a/packages/nextcloud/lib/src/client.dart +++ b/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(), + userAgent: userAgentOverride ?? appType.userAgent, authentication: username != null && password != null ? HttpBasicAuthentication( username: username, diff --git a/packages/nextcloud/lib/src/nextcloud.openapi.dart b/packages/nextcloud/lib/src/nextcloud.openapi.dart index 5c4e956f..d61ca963 100644 --- a/packages/nextcloud/lib/src/nextcloud.openapi.dart +++ b/packages/nextcloud/lib/src/nextcloud.openapi.dart @@ -93,6 +93,7 @@ class Client { Client( this.baseURL, { Map? 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; From 66df471243a25024e827012eaa9fd4c08e941536 Mon Sep 17 00:00:00 2001 From: jld3103 Date: Thu, 8 Dec 2022 14:14:09 +0100 Subject: [PATCH 2/2] neon: Fix user agent in debug builds --- packages/neon/lib/src/models/account.dart | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/neon/lib/src/models/account.dart b/packages/neon/lib/src/models/account.dart index d58cacd9..a28d84f1 100644 --- a/packages/neon/lib/src/models/account.dart +++ b/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 {