Files
openchamber-android-native/tool/proxy_probe.dart
T
blumia 55dac37baf 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.
2026-11-18 22:18:45 +08:00

53 lines
1.7 KiB
Dart

// A probe for the Dart client's proxy support, run with:
// dart run tool/proxy_probe.dart
// It talks to a local OpenChamber server directly and through the local
// SOCKS5 (1080) and HTTP (8081) test proxies.
import 'dart:io';
import 'package:openchamber/api/client.dart';
Future<void> probe(String? proxy) async {
final label = proxy ?? 'direct';
final client = Client(Uri.parse('http://127.0.0.1:3000'), proxy: proxy);
final sw = Stopwatch()..start();
try {
final status = await client.sessionStatus().timeout(const Duration(seconds: 15));
final page = await client
.listSessions(limit: 3)
.timeout(const Duration(seconds: 15));
print('OK $label auth=${status['authenticated']} '
'sessions=${page.data.length} ${sw.elapsedMilliseconds}ms');
} on Object catch (e) {
print('FAIL $label ${e.toString().split('\n').first}');
} finally {
client.close();
}
}
Future<void> probeStream(String? proxy) async {
final label = proxy ?? 'direct';
final client = Client(Uri.parse('http://127.0.0.1:3000'), proxy: proxy);
try {
final ev = await client
.streamEvents(types: ['session.execution.started'])
.first
.timeout(const Duration(seconds: 10));
print('OK sse $label ${ev['type']}');
} on Object catch (e) {
print('FAIL sse $label ${e.toString().split('\n').first}');
} finally {
client.close();
}
}
Future<void> main() async {
await probe(null);
await probe('socks5://127.0.0.1:1080');
await probe('socks5h://127.0.0.1:1080');
await probe('http://127.0.0.1:8081');
await probe('socks5://127.0.0.1:1');
await probeStream('socks5://127.0.0.1:1080');
await probeStream('http://127.0.0.1:8081');
exit(0);
}