fix: working HTTP and SOCKS5 proxies; save only working servers

- SOCKS5 had been fed to HttpClient.findProxy, which supports only HTTP
  proxies ("Invalid proxy configuration"), and socks5h was treated as an
  HTTP proxy ("Invalid request method"). HTTP/HTTPS proxies stay on
  findProxy; socks5/socks5h tunnel through socks5_proxy, which resolves
  names at the proxy; user:pass in the proxy URL is passed along.
- Saving moved to the successful path: a failed attempt stays in the form
  with a short reason, and the server list keeps no duplicates.
- package net.blumia.openchamber.flutter (namespace, applicationId,
  MainActivity, iOS bundle id), version 0.3.1 (code 301).
- show the proxy in the instance and server lists; clearer connect errors.
- tool/proxy_probe.dart checks direct, socks5, socks5h and HTTP proxies
  (requests and SSE) against a live server.
This commit is contained in:
blumia committed 2026-11-18 22:18:45 +08:00
1 parent 782ac2bd4d
commit 55dac37baf
12 files changed
+227 -46

No files matched your search

+25 -2
View File
@@ -3,6 +3,7 @@
library;
import 'dart:async';
import 'dart:io';
import 'package:flutter/foundation.dart';
@@ -109,15 +110,37 @@ class AppState extends ChangeNotifier {
_connected(cl, c);
} catch (e) {
busy = false;
error = e.toString();
error = friendlyConnectError(e);
if (!silent) {
// Surface in the form: the UI reads error itself.
_lastError = e.toString();
_lastError = error;
}
notifyListeners();
}
}
/// A short, actionable message for a failed connect.
String friendlyConnectError(Object e) {
if (e is ApiError) return e.message;
if (e is ArgumentError) return e.message?.toString() ?? e.toString();
if (e is TimeoutException) return '连接超时:检查服务器与代理地址';
final s = e.toString();
if (e is SocketException) {
if (s.contains('Connection refused')) {
return '连接被拒绝:服务器或代理未启动,或端口不对';
}
if (s.contains('Failed host lookup') || s.contains('nodename nor servname')) {
return '无法解析地址:检查服务器或代理主机名';
}
if (s.contains('Network is unreachable')) return '网络不可达';
if (s.contains('Connection closed') || s.contains('reset by peer')) {
return '连接被断开:检查代理是否可用';
}
return '网络错误:$s';
}
return s;
}
String? _lastError;
String? get lastError => _lastError;
void clearLastError() => _lastError = null;