-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Setup Proxy if proxy found in devices
(cherry picked from commit beeb717)
- Loading branch information
Showing
5 changed files
with
77 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* LinShare is an open source filesharing software, part of the LinPKI software | ||
* suite, developed by Linagora. | ||
* | ||
* Copyright (C) 2023 LINAGORA | ||
* | ||
* This program is free software: you can redistribute it and/or modify it under the | ||
* terms of the GNU Affero General Public License as published by the Free Software | ||
* Foundation, either version 3 of the License, or (at your option) any later version, | ||
* provided you comply with the Additional Terms applicable for LinShare software by | ||
* Linagora pursuant to Section 7 of the GNU Affero General Public License, | ||
* subsections (b), (c), and (e), pursuant to which you must notably (i) retain the | ||
* display in the interface of the “LinShare™” trademark/logo, the "Libre & Free" mention, | ||
* the words “You are using the Free and Open Source version of LinShare™, powered by | ||
* Linagora © 2009–2021. Contribute to Linshare R&D by subscribing to an Enterprise | ||
* offer!”. You must also retain the latter notice in all asynchronous messages such as | ||
* e-mails sent with the Program, (ii) retain all hypertext links between LinShare and | ||
* http://www.linshare.org, between linagora.com and Linagora, and (iii) refrain from | ||
* infringing Linagora intellectual property rights over its trademarks and commercial | ||
* brands. Other Additional Terms apply, see | ||
* <http://www.linshare.org/licenses/LinShare-License_AfferoGPL-v3.pdf> | ||
* for more details. | ||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY | ||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for | ||
* more details. | ||
* You should have received a copy of the GNU Affero General Public License and its | ||
* applicable Additional Terms for LinShare along with this program. If not, see | ||
* <http://www.gnu.org/licenses/> for the GNU Affero General Public License version | ||
* 3 and <http://www.linshare.org/licenses/LinShare-License_AfferoGPL-v3.pdf> for | ||
* the Additional Terms applicable to LinShare software. | ||
*/ | ||
|
||
import 'dart:developer'; | ||
import 'dart:io'; | ||
|
||
import 'package:dio/adapter.dart'; | ||
import 'package:dio/dio.dart'; | ||
import 'package:linshare_flutter_app/presentation/di/get_it_service.dart'; | ||
import 'package:native_flutter_proxy/native_proxy_reader.dart'; | ||
|
||
Future<void> setUpProxy() async { | ||
try { | ||
final settings = await NativeProxyReader.proxySetting; | ||
log('::setUpProxy(): enable = ${settings.enabled}, host = ${settings.host}, port = ${settings.port}'); | ||
if (settings.enabled && settings.host != null) { | ||
if (Platform.isAndroid) { | ||
(getIt<Dio>().httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate = (HttpClient client) { | ||
client.badCertificateCallback = (X509Certificate cert, String host, int port) { | ||
log('Bad certificate callback called. $host:$port. cert: ${cert.subject}'); | ||
return true; | ||
}; | ||
client.findProxy = (url) { | ||
log('::setUpProxy(): $url'); | ||
return HttpClient.findProxyFromEnvironment( | ||
url, | ||
environment: {'https_proxy': '${settings.host}:${settings.port}'} | ||
); | ||
}; | ||
return client; | ||
}; | ||
} | ||
} | ||
} catch (e) { | ||
log('::setUpProxy() exception: $e'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ dependencies: | |
|
||
# Http client | ||
dio: 4.0.0 | ||
native_flutter_proxy: 0.1.15 | ||
json_annotation: 4.4.0 | ||
|
||
#get_it | ||
|