Closed tomekit closed 1 year ago
Can you share more info on the proxy override method that you use, source code and settings would be great. I'm not familiar with it. Thank you!
Hi Sebastian, I am very new to Flutter environment, so please forgive my ignorance.
Basically flutter allows to set global proxy using findProxy
:
https://api.flutter.dev/flutter/dart-io/HttpClient/findProxy.html
Example code:
lib/proxy-http-overrides.dart
import 'dart:io';
class ProxyHttpOverrides extends HttpOverrides {
@override
HttpClient createHttpClient(SecurityContext? context) {
final client = super.createHttpClient(context);
const charlesIp = String.fromEnvironment('CHARLES_PROXY_IP', defaultValue: "");
if (charlesIp == "") return client;
client.findProxy = (uri) => "PROXY $charlesIp:8888;";
client.badCertificateCallback = (X509Certificate cert, String host, int port) => true;
return client;
}
}
main.dart
void appRunner(AppConfig appConfig) async {
HttpOverrides.global = ProxyHttpOverrides();
...
}
Charles part is pretty irrelevant, it's just one of the popular proxies, but you can use any HTTP compatible proxy.
My use case is to debug the all application's outgoing HTTP requests and I've already managed to find a way around by adding additional logs in the part of the code that uses the flutter_uploaded
component.
Also, in some protected corporate environments outbound traffic is possible only via designated proxy, in which case it would be useful to specify the proxy.
I am going to keep this open in case someone is facing similar problem.
Thanks !
@tomekit there is no way to specify a Proxy at the moment. The actual network communication is done using native methods and the Proxy would need to be set there.
Thanks, I see, in which case this small feature would actually require modifying both Java's (OkHttpClient - https://stackoverflow.com/a/38252304/2263395) and Swift's equivalent (https://stackoverflow.com/questions/16847858/ios-any-body-knows-how-to-add-a-proxy-to-nsurlrequest), then the proxy would actually have to be passed from the Dart to the native methods.
I register my proxy in
main.dart
like this:Unfortunately anything that goes through:
flutter_uploader
isn't captured.Request coming from other libaries,
Dio
orcached_network_image
work just fine.Is there a way to pass down the proxy settings, so the proxy works from the:
com.bluechilli.flutteruploader.UploadWorker
?