diff --git a/lib/network/components/script_manager.dart b/lib/network/components/script_manager.dart index 2fd8855..e98349b 100644 --- a/lib/network/components/script_manager.dart +++ b/lib/network/components/script_manager.dart @@ -313,6 +313,10 @@ async function onResponse(context, request, response) { request.uri = Uri.parse('${request.remoteDomain()}${map['path']}?$query').toString(); map['headers'].forEach((key, value) { + if (value is List) { + request.headers.addValues(key, value.map((e) => e.toString()).toList()); + return; + } request.headers.add(key, value); }); request.body = map['body'] == null ? null : utf8.encode(map['body'].toString()); @@ -324,6 +328,11 @@ async function onResponse(context, request, response) { response.headers.clear(); response.status = HttpStatus.valueOf(map['statusCode']); map['headers'].forEach((key, value) { + if (value is List) { + response.headers.addValues(key, value.map((e) => e.toString()).toList()); + return; + } + response.headers.add(key, value); }); response.headers.remove(HttpHeaders.CONTENT_ENCODING); diff --git a/lib/network/handler.dart b/lib/network/handler.dart index a59f2c0..620434a 100644 --- a/lib/network/handler.dart +++ b/lib/network/handler.dart @@ -25,6 +25,7 @@ import 'package:network_proxy/network/http/http.dart'; import 'package:network_proxy/network/http/websocket.dart'; import 'package:network_proxy/network/proxy_helper.dart'; import 'package:network_proxy/network/util/attribute_keys.dart'; +import 'package:network_proxy/network/util/localizations.dart'; import 'package:network_proxy/network/util/logger.dart'; import 'package:network_proxy/network/util/uri.dart'; import 'package:network_proxy/utils/ip.dart'; @@ -51,7 +52,6 @@ class HttpProxyChannelHandler extends ChannelHandler { @override void channelRead(ChannelContext channelContext, Channel channel, HttpRequest msg) async { - //下载证书 if (msg.uri == 'http://proxy.pin/ssl' || msg.requestUrl == 'http://127.0.0.1:${channel.socket.port}/ssl') { ProxyHelper.crtDownload(channel, msg); @@ -253,7 +253,7 @@ class HttpResponseProxyHandler extends ChannelHandler { } msg = response; } catch (e, t) { - msg.status = HttpStatus(-1, '执行脚本异常'); + msg.status = HttpStatus(-1, Localizations.isEN ? 'Script exec error' : '执行脚本异常'); msg.body = "$e\n${msg.bodyAsString}".codeUnits; log.e('[${clientChannel.id}] 执行脚本异常 ', error: e, stackTrace: t); } diff --git a/lib/network/proxy_helper.dart b/lib/network/proxy_helper.dart index cc3206c..c68d1c5 100644 --- a/lib/network/proxy_helper.dart +++ b/lib/network/proxy_helper.dart @@ -10,6 +10,7 @@ import 'package:network_proxy/network/http/codec.dart'; import 'package:network_proxy/network/http/http.dart'; import 'package:network_proxy/network/http/http_headers.dart'; import 'package:network_proxy/network/util/file_read.dart'; +import 'package:network_proxy/network/util/localizations.dart'; import 'components/host_filter.dart'; @@ -71,7 +72,8 @@ class ProxyHelper { String message = error.toString(); HttpStatus status = HttpStatus(-1, message); if (error is HandshakeException) { - status = HttpStatus(-2, 'SSL握手失败'); + status = HttpStatus( + -2, Localizations.isEN ? 'SSL handshake failed, please check the certificate' : 'SSL握手失败,请检查证书安装是否正确'); } else if (error is ParserException) { status = HttpStatus(-3, error.message); } else if (error is SocketException) { diff --git a/lib/network/util/localizations.dart b/lib/network/util/localizations.dart new file mode 100644 index 0000000..776df69 --- /dev/null +++ b/lib/network/util/localizations.dart @@ -0,0 +1,8 @@ +import 'package:network_proxy/ui/configuration.dart'; + +class Localizations { + + static bool get isEN { + return AppConfiguration.current?.language?.languageCode == 'en'; + } +}