Skip to content

Commit

Permalink
mobile favorite title color & android proxy default port
Browse files Browse the repository at this point in the history
  • Loading branch information
wanghongenpin committed Aug 25, 2024
1 parent 3bc63de commit 80cd8b9
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 9 additions & 3 deletions lib/network/host_port.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion lib/network/http/http.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
22 changes: 20 additions & 2 deletions lib/ui/mobile/request/favorite.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -94,15 +95,32 @@ 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() ?? ''} ';
return ListTile(
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: [
Expand Down
6 changes: 3 additions & 3 deletions lib/ui/mobile/request/request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,17 @@ class RequestRowState extends State<RequestRow> {

@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() ?? '';
var packagesSize = getPackagesSize(request, response);

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),
Expand Down
2 changes: 2 additions & 0 deletions test/http_test.dart
Original file line number Diff line number Diff line change
@@ -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;
Expand Down

0 comments on commit 80cd8b9

Please sign in to comment.