mirror of
https://github.com/wanghongenpin/proxypin.git
synced 2026-05-08 00:24:16 +08:00
Script headers support multiple values #259
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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<HttpRequest> {
|
||||
|
||||
@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<HttpResponse> {
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
8
lib/network/util/localizations.dart
Normal file
8
lib/network/util/localizations.dart
Normal file
@@ -0,0 +1,8 @@
|
||||
import 'package:network_proxy/ui/configuration.dart';
|
||||
|
||||
class Localizations {
|
||||
|
||||
static bool get isEN {
|
||||
return AppConfiguration.current?.language?.languageCode == 'en';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user