@@ -2,6 +2,7 @@ import 'dart:io';
2
2
import 'dart:math';
3
3
import 'package:http/http.dart' as http;
4
4
import 'package:package_info_plus/package_info_plus.dart';
5
+ import 'package:device_info_plus/device_info_plus.dart';
5
6
import 'package:http/io_client.dart';
6
7
import 'client_mixin.dart';
7
8
import 'client_base.dart';
@@ -89,6 +90,59 @@ class ClientIO extends ClientBase with ClientMixin {
89
90
_headers![key] = value;
90
91
return this;
91
92
}
93
+
94
+ Future init() async {
95
+ if (_initProgress) return;
96
+ _initProgress = true;
97
+ final Directory cookieDir = await _getCookiePath();
98
+ _cookieJar = PersistCookieJar(storage: FileStorage(cookieDir.path));
99
+ _interceptors.add(CookieManager(_cookieJar));
100
+
101
+ var device = '';
102
+ try {
103
+ PackageInfo packageInfo = await PackageInfo.fromPlatform();
104
+ addHeader(
105
+ 'Origin',
106
+ '{{spec .title | caseLower }}-${Platform.operatingSystem}://${packageInfo.packageName}',
107
+ );
108
+
109
+ //creating custom user agent
110
+ DeviceInfoPlugin deviceInfoPlugin = DeviceInfoPlugin();
111
+ if (Platform.isAndroid) {
112
+ final andinfo = await deviceInfoPlugin.androidInfo;
113
+ device =
114
+ '(Linux; U; Android ${andinfo.version.release}; ${andinfo.brand} ${andinfo.model})';
115
+ }
116
+ if (Platform.isIOS) {
117
+ final iosinfo = await deviceInfoPlugin.iosInfo;
118
+ device = '${iosinfo.utsname.machine} iOS/${iosinfo.systemVersion}';
119
+ }
120
+ if (Platform.isLinux) {
121
+ final lininfo = await deviceInfoPlugin.linuxInfo;
122
+ device = '(Linux; U; ${lininfo.id} ${lininfo.version})';
123
+ }
124
+ if (Platform.isWindows) {
125
+ final wininfo = await deviceInfoPlugin.windowsInfo;
126
+ device =
127
+ '(Windows NT; ${wininfo.computerName})'; //can't seem to get much info here
128
+ }
129
+ if (Platform.isMacOS) {
130
+ final macinfo = await deviceInfoPlugin.macOsInfo;
131
+ device = '(Macintosh; ${macinfo.model})';
132
+ }
133
+ addHeader(
134
+ 'user-agent',
135
+ '${packageInfo.packageName}/${packageInfo.version} $device',
136
+ );
137
+ } catch (e) {
138
+ debugPrint('Error getting device info: $e');
139
+ device = Platform.operatingSystem;
140
+ addHeader('user-agent', '$device');
141
+ }
142
+
143
+ _initialized = true;
144
+ _initProgress = false;
145
+ }
92
146
93
147
@override
94
148
Future<Response > chunkedUpload({
0 commit comments