You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Maurice Raguse 4cd1900eff migrate to nullSafety 3 years ago
android first blood 5 years ago
example migrate to nullSafety 3 years ago
ios first blood 5 years ago
lib migrate to nullSafety 3 years ago
test migrate to nullSafety 3 years ago
.gitignore rm lock 5 years ago
.metadata first blood 5 years ago
CHANGELOG.md first blood 5 years ago
LICENSE first blood 5 years ago
README.md first blood 5 years ago
pubspec.yaml migrate to nullSafety 3 years ago

README.md

system_proxy

A Flutter Plugin to get system proxy setting. It is used to proxy for Flutter and Dart HttpClient request。Because Dart HttpClient is adapting the system proxy setting automatically in default, it's difficult to grab requests for testing .

获取系统代理配置。 可用于为flutter的Dart HttpClient的请求设置代理因为默认Dart请求不会理睬系统代理配置这对于抓取请求来进行测试等场景造成不小困难。

Getting Started

Install

Please add the plugin to pubspec.yaml.

Caution

It's useful for Android >= 23 .

Usage

Import

import 'package:system_proxy/system_proxy.dart';

Code

// the proxy value likes:  {port: 8899, host: 127.0.0.1}
Map<String, String> proxy = await SystemProxy.getProxySettings();
if (proxy != null) {
    print('proxy $proxy');
}

Setting Proxy for HttpClient

class ProxiedHttpOverrides extends HttpOverrides {
  String _port;
  String _host;
  ProxiedHttpOverrides(this._host, this._port);

  @override
  HttpClient createHttpClient(SecurityContext context) {
    return super.createHttpClient(context)
      // set proxy
      ..findProxy = (uri) {
        return _host != null ? "PROXY $_host:$_port;" : 'DIRECT';
      };
  }
}

void main() async {
  Map<String, String> proxy = await SystemProxy.getProxySettings();
  if (proxy == null) {
    proxy = {
    'host': null,
    'port': null
    };
  }
  HttpOverrides.global = new ProxiedHttpOverrides(proxy['host'], proxy['port']);
  runApp(MyApp());
}