Skip to content

Repository files navigation

Flutter System Proxy

A Flutter Plugin to detect System proxy. When using HTTP client that are not proxy aware this plugin can help with finding the proxy from system settings which then can be used with HTTP Client to make a successful request.

Getting Started

Installation

Add flutter_system_proxy to your pubspec.yaml:

dependencies:
flutter_system_proxy: ^0.2.0

Then run:

flutter pub get

Alternatively, install from the command line:

flutter pub add flutter_system_proxy

Basic Usage (Example With Dio)

import'package:flutter_system_proxy/flutter_system_proxy.dart';
...
var dio =newDio();
var url ="http://....";
var proxy =awaitFlutterSystemProxy.findProxyFromEnvironment(url);
(dio.httpClientAdapter asDefaultHttpClientAdapter).onHttpClientCreate =
(HttpClient client) {
client.findProxy = (uri) {
return proxy;
};
};
var response =await dio.get(url);

Advanced Usage (Custom Dio Adapter)

// Create a custom adapter that can help resolve proxy based on urls // (This is important as in some senerio there are PAC files which might have different proxy based on different urls)classMyAdapterextendsHttpClientAdapter {
finalDefaultHttpClientAdapter _adapter =DefaultHttpClientAdapter();
@overrideFuture<ResponseBody> fetch(RequestOptions options,
Stream<Uint8List>? requestStream, Future? cancelFuture) async {
var uri = options.uri;
var proxy =awaitFlutterSystemProxy.findProxyFromEnvironment(uri.toString()); // This line does the magic
_adapter.onHttpClientCreate = (HttpClient clinet) {
clinet.findProxy = (uri) {
return proxy;
};
};
return _adapter.fetch(options, requestStream, cancelFuture);
}
@overridevoidclose({bool force =false}) {
_adapter.close(force: force);
}
}
// Use a wrapper around getting diovoidgetDio(){
var dio =Dio();
dio.httpClientAdapter =MyAdapter();
return dio;
}

About

A Flutter Plugin to detect System proxy. When using HTTP client that are not proxy aware this plugin can help with finding the proxy from system settings which then can be used with HTTP Client to make a successful request.

Resources

Stars

13 stars

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages