Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-11-20 19:45:55 +08:00
parent c8de503fae
commit 460a8262c1
2 changed files with 10 additions and 15 deletions

View File

@@ -92,6 +92,7 @@ class Request {
* config it and create
*/
Request._internal() {
final enableHttp2 = Pref.enableHttp2;
//BaseOptions、Options、RequestOptions 都可以配置参数,优先级别依次递增,且可以根据优先级别覆盖参数
BaseOptions options = BaseOptions(
//请求基地址,可以包含子路径
@@ -103,7 +104,7 @@ class Request {
//Http请求头.
headers: {
'user-agent': 'Dart/3.6 (dart:io)', // Http2Adapter不会自动添加标头
if (!Pref.enableHttp2) 'connection': 'keep-alive',
if (!enableHttp2) 'connection': 'keep-alive',
'accept-encoding': 'br,gzip',
},
responseDecoder: _responseDecoder, // Http2Adapter没有自动解压
@@ -127,31 +128,25 @@ class Request {
..idleTimeout = const Duration(seconds: 15)
..autoUncompress = false
..findProxy = ((_) => 'PROXY $systemProxyHost:$systemProxyPort')
..badCertificateCallback =
(X509Certificate cert, String host, int port) => true
..badCertificateCallback = (cert, host, port) => true
: () => HttpClient()
..idleTimeout = const Duration(seconds: 15)
..autoUncompress = false, // Http2Adapter没有自动解压, 统一行为
);
late final Uri proxy;
if (enableSystemProxy) {
proxy = Uri(
scheme: 'http',
host: systemProxyHost,
port: systemProxyPort,
);
}
dio = Dio(options)
..httpClientAdapter = Pref.enableHttp2
..httpClientAdapter = enableHttp2
? Http2Adapter(
ConnectionManager(
idleTimeout: const Duration(seconds: 15),
onClientCreate: enableSystemProxy
? (_, config) {
config
..proxy = proxy
..proxy = Uri(
scheme: 'http',
host: systemProxyHost,
port: systemProxyPort,
)
..onBadCertificate = (_) => true;
}
: Pref.badCertificateCallback