2024-08-26 20:44:30 +08:00
|
|
|
import 'dart:io';
|
|
|
|
|
|
2025-02-09 18:39:38 +08:00
|
|
|
import 'package:fl_clash/common/common.dart';
|
2025-12-16 11:23:09 +08:00
|
|
|
import 'package:fl_clash/controller.dart';
|
2024-08-26 20:44:30 +08:00
|
|
|
|
|
|
|
|
class FlClashHttpOverrides extends HttpOverrides {
|
2025-03-05 16:08:50 +08:00
|
|
|
static String handleFindProxy(Uri url) {
|
|
|
|
|
if ([localhost].contains(url.host)) {
|
2025-06-07 01:48:34 +08:00
|
|
|
return 'DIRECT';
|
2025-03-05 16:08:50 +08:00
|
|
|
}
|
2025-12-16 11:23:09 +08:00
|
|
|
final port = appController.config.patchClashConfig.mixedPort;
|
|
|
|
|
final isStart = appController.isStart;
|
2025-06-07 01:48:34 +08:00
|
|
|
commonPrint.log('find $url proxy:$isStart');
|
|
|
|
|
if (!isStart) return 'DIRECT';
|
|
|
|
|
return 'PROXY localhost:$port';
|
2025-03-05 16:08:50 +08:00
|
|
|
}
|
|
|
|
|
|
2024-08-26 20:44:30 +08:00
|
|
|
@override
|
|
|
|
|
HttpClient createHttpClient(SecurityContext? context) {
|
|
|
|
|
final client = super.createHttpClient(context);
|
2025-07-31 17:09:18 +08:00
|
|
|
client.badCertificateCallback = (_, _, _) => true;
|
2025-03-05 16:08:50 +08:00
|
|
|
client.findProxy = handleFindProxy;
|
2024-08-26 20:44:30 +08:00
|
|
|
return client;
|
|
|
|
|
}
|
|
|
|
|
}
|