diff --git a/android/app/src/main/kotlin/com/network/proxy/vpn/ConnectionManager.kt b/android/app/src/main/kotlin/com/network/proxy/vpn/ConnectionManager.kt index 48187629..eaeb30af 100644 --- a/android/app/src/main/kotlin/com/network/proxy/vpn/ConnectionManager.kt +++ b/android/app/src/main/kotlin/com/network/proxy/vpn/ConnectionManager.kt @@ -98,9 +98,9 @@ class ConnectionManager private constructor() : CloseableConnection { connection.channel = channel var socketAddress: SocketAddress? = null - if (DEFAULT_PORTS.contains(port)) { - socketAddress = proxyAddress - } +// if (DEFAULT_PORTS.contains(port)) { +// socketAddress = proxyAddress +// } connection.isInitConnect = socketAddress != null diff --git a/lib/network/host_port.dart b/lib/network/host_port.dart index 9a7c2336..d674214a 100644 --- a/lib/network/host_port.dart +++ b/lib/network/host_port.dart @@ -55,9 +55,15 @@ class HostAndPort { String? scheme; //域名格式 直接解析 if (schemes.any((scheme) => url.startsWith(scheme))) { - //httpScheme - scheme = schemes.firstWhere((element) => url.startsWith(element),orElse: () => httpScheme); - domain = url.substring(scheme.length).split("/")[0]; + try { + Uri uri = Uri.parse(url); + return HostAndPort('${uri.scheme}://', uri.host, uri.port); + } catch (e) { + //httpScheme + scheme = schemes.firstWhere((element) => url.startsWith(element), orElse: () => httpScheme); + domain = url.substring(scheme.length).split("/")[0]; + } + //说明支持ipv6 if (domain.startsWith('[') && domain.endsWith(']')) { return HostAndPort(scheme, domain, scheme == httpScheme ? 80 : 443); diff --git a/lib/network/http/http.dart b/lib/network/http/http.dart index 4555bd9b..5868b1df 100644 --- a/lib/network/http/http.dart +++ b/lib/network/http/http.dart @@ -152,7 +152,9 @@ class HttpRequest extends HttpMessage { HttpRequest copy({String? uri}) { var request = HttpRequest(method, uri ?? this.uri, protocolVersion: protocolVersion); request.headers.addAll(headers); - request.hostAndPort = uri == null ? hostAndPort : HostAndPort.of(uri); + if (uri != null && !uri.startsWith('/')) { + request.hostAndPort = HostAndPort.of(uri); + } request.body = body; return request; } diff --git a/lib/ui/mobile/request/favorite.dart b/lib/ui/mobile/request/favorite.dart index cc13d63a..4919592d 100644 --- a/lib/ui/mobile/request/favorite.dart +++ b/lib/ui/mobile/request/favorite.dart @@ -15,6 +15,7 @@ import 'package:network_proxy/ui/content/panel.dart'; import 'package:network_proxy/ui/mobile/request/repeat.dart'; import 'package:network_proxy/ui/mobile/request/request_editor.dart'; import 'package:network_proxy/utils/curl.dart'; +import 'package:network_proxy/utils/lang.dart'; import 'package:network_proxy/utils/python.dart'; import 'package:shared_preferences/shared_preferences.dart'; @@ -94,7 +95,24 @@ class _FavoriteItemState extends State<_FavoriteItem> { @override Widget build(BuildContext context) { var response = request.response; - var title = '${request.method.name} ${request.requestUrl}'; + Widget? title = widget.favorite.name?.isNotEmpty == true + ? Text(widget.favorite.name!, + overflow: TextOverflow.ellipsis, + maxLines: 1, + style: TextStyle(fontSize: 14, color: Colors.blueAccent.shade200)) + : Text.rich( + overflow: TextOverflow.ellipsis, + maxLines: 2, + TextSpan(children: [ + TextSpan(text: '${request.method.name} ', style: const TextStyle(fontSize: 14, color: Colors.teal)), + TextSpan( + text: '${request.remoteDomain()}${request.path()}'.fixAutoLines(), + style: TextStyle(fontSize: 14, color: Colors.blueAccent.shade200)), + TextSpan( + text: '?${request.requestUri?.query}', + style: TextStyle(fontSize: 14, color: Colors.pinkAccent.shade200)), + ])); + var time = formatDate(request.requestTime, [mm, '-', d, ' ', HH, ':', nn, ':', ss]); String subtitle = '$time - [${response?.status.code ?? ''}] ${response?.contentType.name.toUpperCase() ?? ''} ${response?.costTime() ?? ''} '; @@ -102,7 +120,7 @@ class _FavoriteItemState extends State<_FavoriteItem> { onLongPress: menu, minLeadingWidth: 25, leading: getIcon(response), - title: Text(widget.favorite.name ?? title, overflow: TextOverflow.ellipsis, maxLines: 2), + title: title, subtitle: Text.rich( maxLines: 1, TextSpan(children: [ diff --git a/lib/ui/mobile/request/request.dart b/lib/ui/mobile/request/request.dart index 3cddd8ea..5fb7e422 100644 --- a/lib/ui/mobile/request/request.dart +++ b/lib/ui/mobile/request/request.dart @@ -67,9 +67,9 @@ class RequestRowState extends State { @override Widget build(BuildContext context) { - String path = widget.displayDomain ? '${request.remoteDomain()}${request.path()}' : request.path(); + String url = widget.displayDomain ? request.requestUrl : request.path(); - var title = Strings.autoLineString('${request.method.name} $path'); + var title = Strings.autoLineString('${request.method.name} $url'); var time = formatDate(request.requestTime, [HH, ':', nn, ':', ss]); var contentType = response?.contentType.name.toUpperCase() ?? ''; @@ -77,7 +77,7 @@ class RequestRowState extends State { var subTitle = '$time - [${response?.status.code ?? ''}] $contentType $packagesSize ${response?.costTime() ?? ''}'; - var highlightColor = KeywordHighlight.getHighlightColor(path); + var highlightColor = KeywordHighlight.getHighlightColor(url); return ListTile( visualDensity: const VisualDensity(vertical: -4), diff --git a/test/http_test.dart b/test/http_test.dart index 4429a2b9..e8ade12c 100644 --- a/test/http_test.dart +++ b/test/http_test.dart @@ -1,11 +1,13 @@ import 'dart:io'; main() async { + print(Uri.parse("https://www.v2ex.com").scheme); // await socketTest(); await webTest(); } webTest() async { + var httpClient = HttpClient(); httpClient.findProxy = (uri) => "PROXY 127.0.0.1:7890"; // httpClient.badCertificateCallback = (X509Certificate cert, String host, int port) => true;