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-03-05 16:08:50 +08:00
|
|
|
import 'package:fl_clash/state.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)) {
|
|
|
|
|
return "DIRECT";
|
|
|
|
|
}
|
|
|
|
|
final port = globalState.config.patchClashConfig.mixedPort;
|
|
|
|
|
final isStart = globalState.appState.runTime != null;
|
|
|
|
|
commonPrint.log("find $url proxy:$isStart");
|
|
|
|
|
if (!isStart) return "DIRECT";
|
|
|
|
|
return "PROXY localhost:$port";
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-26 20:44:30 +08:00
|
|
|
@override
|
|
|
|
|
HttpClient createHttpClient(SecurityContext? context) {
|
|
|
|
|
final client = super.createHttpClient(context);
|
2025-05-02 02:24:12 +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;
|
|
|
|
|
}
|
|
|
|
|
}
|