diff --git a/lib/network/http_client.dart b/lib/network/http_client.dart index f81fe51..c1b1475 100644 --- a/lib/network/http_client.dart +++ b/lib/network/http_client.dart @@ -119,9 +119,11 @@ class HttpClients { /// 发送代理请求 static Future proxyRequest(HttpRequest request, {ProxyInfo? proxyInfo, Duration timeout = const Duration(seconds: 10)}) async { + if (request.headers.host == null || request.headers.host?.trim().isEmpty == true) { try { - request.headers.host = '${Uri.parse(request.uri).host}:${Uri.parse(request.uri).port}'; + var uri = Uri.parse(request.uri); + request.headers.host = '${Uri.parse(request.uri).host}${uri.hasPort ? ':${uri.port}' : ''}'; } catch (_) {} } request.protocolVersion = 'HTTP/1.1'; @@ -129,7 +131,6 @@ class HttpClients { ChannelContext channelContext = ChannelContext(); var httpResponseHandler = HttpResponseHandler(); HostAndPort hostPort = HostAndPort.of(request.uri); - print("proxyRequest $proxyInfo ${request.uri}"); Channel channel = await proxyConnect(proxyInfo: proxyInfo, hostPort, httpResponseHandler, channelContext); diff --git a/lib/network/network.dart b/lib/network/network.dart index 200a8c3..0891c33 100644 --- a/lib/network/network.dart +++ b/lib/network/network.dart @@ -168,15 +168,13 @@ class Server extends Network { channel.serverSecureSocket(secureSocket, channelContext); } catch (error, trace) { try { - channelContext.processInfo = + channelContext.processInfo ??= await ProcessInfoUtils.getProcessByPort(channel.remoteSocketAddress, hostAndPort?.domain ?? 'unknown'); } catch (ignore) { /*ignore*/ } - if (error is HandshakeException) { - channelContext.host = hostAndPort; - } + channelContext.host ??= hostAndPort; channel.pipeline.exceptionCaught(channelContext, channel, error, trace: trace); } } diff --git a/lib/ui/desktop/request/request_editor.dart b/lib/ui/desktop/request/request_editor.dart index da384ca..b465ac9 100644 --- a/lib/ui/desktop/request/request_editor.dart +++ b/lib/ui/desktop/request/request_editor.dart @@ -139,9 +139,10 @@ class RequestEditorState extends State { var currentState = requestLineKey.currentState!; var headers = requestKey.currentState?.getHeaders(); var requestBody = requestKey.currentState?.getBody(); + String url = currentState.requestUrl.text; HttpRequest request = - HttpRequest(HttpMethod.valueOf(currentState.requestMethod), Uri.encodeFull(currentState.requestUrl.text)); + HttpRequest(HttpMethod.valueOf(currentState.requestMethod), Uri.parse(url).toString()); request.headers.addAll(headers); request.body = requestBody == null ? null : utf8.encode(requestBody); diff --git a/lib/ui/mobile/request/request_editor.dart b/lib/ui/mobile/request/request_editor.dart index a73dfb2..c11f34a 100644 --- a/lib/ui/mobile/request/request_editor.dart +++ b/lib/ui/mobile/request/request_editor.dart @@ -154,9 +154,9 @@ class RequestEditorState extends State with SingleTickerPro var currentState = requestLineKey.currentState!; var headers = requestKey.currentState?.getHeaders(); var requestBody = requestKey.currentState?.getBody(); + String url = currentState.requestUrl.text; - HttpRequest request = - HttpRequest(HttpMethod.valueOf(currentState.requestMethod), Uri.encodeFull(currentState.requestUrl.text)); + HttpRequest request = HttpRequest(HttpMethod.valueOf(currentState.requestMethod), Uri.parse(url).toString()); request.headers.addAll(headers); request.body = requestBody == null ? null : utf8.encode(requestBody); diff --git a/linux/build.sh b/linux/build.sh index e9496fc..26c291e 100644 --- a/linux/build.sh +++ b/linux/build.sh @@ -1,6 +1,5 @@ #!/bin/bash -#打包deb pwd cd ../build/linux/x64/release rm -rf package diff --git a/pubspec.yaml b/pubspec.yaml index c0c2c0a..c2edd60 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -2,7 +2,7 @@ name: network_proxy description: ProxyPin publish_to: 'none' # Remove this line if you wish to publish to pub.dev -version: 1.1.1+10 +version: 1.1.1+11 environment: sdk: '>=3.0.2 <4.0.0'