Skip to content

Commit

Permalink
Merge pull request #5 from Rushabhshroff/forcelocal-fix
Browse files Browse the repository at this point in the history
Forcelocal fix
  • Loading branch information
Rushabhshroff authored Nov 11, 2021
2 parents 8be1113 + 7f61516 commit 27b50ec
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 26 deletions.
10 changes: 5 additions & 5 deletions android/.settings/org.eclipse.buildship.core.prefs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
arguments=
auto.sync=false
build.scans.enabled=false
connection.gradle.distribution=GRADLE_DISTRIBUTION(VERSION(7.0-rc-1))
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
connection.project.dir=
eclipse.preferences.version=1
gradle.user.home=
java.home=/Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home
java.home=
jvm.arguments=
offline.mode=false
override.workspace.settings=true
show.console.view=true
show.executions.view=true
override.workspace.settings=false
show.console.view=false
show.executions.view=false
21 changes: 6 additions & 15 deletions ios/Classes/SwiftFlutterSystemProxyPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,12 @@ public class SwiftFlutterSystemProxyPlugin: NSObject, FlutterPlugin {
let args = call.arguments as! NSDictionary
let url = args.value(forKey:"url") as! String
let host = args.value(forKey:"host") as! String
let PacUrl = proxyDict.value(forKey:"ProxyAutoConfigURLString") as! String
if let uri = URL(string: PacUrl) {
do {
let contents = try String(contentsOf: uri)
let jsEngine:JSContext = JSContext()
jsEngine.evaluateScript(contents)
let fn = "FindProxyForURL(\"" + url + "\",\""+host+"\")"
let proxy = jsEngine.evaluateScript(fn)
result(proxy?.toString())
} catch {
result("DIRECT")
}
} else {
result("DIRECT")
}
let js = args.value(forKey:"js") as! String
let jsEngine:JSContext = JSContext()
jsEngine.evaluateScript(js)
let fn = "FindProxyForURL(\"" + url + "\",\""+host+"\")"
let proxy = jsEngine.evaluateScript(fn)
result(proxy?.toString())
}else{
result("DIRECT")
}
Expand Down
28 changes: 24 additions & 4 deletions lib/flutter_system_proxy.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'package:flutter/services.dart';

Expand Down Expand Up @@ -32,7 +33,10 @@ class FlutterSystemProxy {
return null;
} else if (Platform.isIOS) {
if (proxySettings["ProxyAutoConfigEnable"] == 1) {
return {"pacEnabled": "true"};
return {
"pacEnabled": "true",
"pacUrl": proxySettings['ProxyAutoConfigURLString']
};
} else {
if (isHttps) {
if (proxySettings['HTTPSEnable'] == 1) {
Expand Down Expand Up @@ -65,9 +69,13 @@ class FlutterSystemProxy {
(parsedProxy["host"] as String) +
":" +
(parsedProxy["port"] as String);
} else if (parsedProxy != null && parsedProxy["pacEnabled"] == "true") {
String proxy =
await _channel.invokeMethod("executePAC", {"url": url, "host": host});
} else if (parsedProxy != null &&
parsedProxy["pacEnabled"] == "true" &&
parsedProxy["pacUrl"] != null) {
String pacLocation = parsedProxy["pacUrl"] as String;
String jsContents = await contents(pacLocation);
String proxy = await _channel.invokeMethod(
"executePAC", {"url": url, "host": host, "js": jsContents});
return proxy;
} else {
return HttpClient.findProxyFromEnvironment(Uri.parse(url));
Expand All @@ -88,3 +96,15 @@ bool isPort(String? port) {
return false;
}
}

Future<String> contents(String url) async {
HttpClient client = new HttpClient();
var completor = new Completer<String>();
client.findProxy = null;
var request = await client.getUrl(Uri.parse(url));
var response = await request.close();
response.transform(utf8.decoder).listen((contents) {
completor.complete(contents);
});
return completor.future;
}
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_system_proxy
description: 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.
version: 0.0.1
version: 0.0.2
homepage: https://github.com/Rushabhshroff/flutter_system_proxy.git

environment:
Expand All @@ -24,4 +24,4 @@ flutter:
ios:
pluginClass: FlutterSystemProxyPlugin



0 comments on commit 27b50ec

Please sign in to comment.