Skip to content

Commit 27b50ec

Browse files
Merge pull request #5 from Rushabhshroff/forcelocal-fix
Forcelocal fix
2 parents 8be1113 + 7f61516 commit 27b50ec

File tree

4 files changed

+37
-26
lines changed

4 files changed

+37
-26
lines changed
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
arguments=
22
auto.sync=false
33
build.scans.enabled=false
4-
connection.gradle.distribution=GRADLE_DISTRIBUTION(VERSION(7.0-rc-1))
4+
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
55
connection.project.dir=
66
eclipse.preferences.version=1
77
gradle.user.home=
8-
java.home=/Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home
8+
java.home=
99
jvm.arguments=
1010
offline.mode=false
11-
override.workspace.settings=true
12-
show.console.view=true
13-
show.executions.view=true
11+
override.workspace.settings=false
12+
show.console.view=false
13+
show.executions.view=false

ios/Classes/SwiftFlutterSystemProxyPlugin.swift

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,12 @@ public class SwiftFlutterSystemProxyPlugin: NSObject, FlutterPlugin {
2121
let args = call.arguments as! NSDictionary
2222
let url = args.value(forKey:"url") as! String
2323
let host = args.value(forKey:"host") as! String
24-
let PacUrl = proxyDict.value(forKey:"ProxyAutoConfigURLString") as! String
25-
if let uri = URL(string: PacUrl) {
26-
do {
27-
let contents = try String(contentsOf: uri)
28-
let jsEngine:JSContext = JSContext()
29-
jsEngine.evaluateScript(contents)
30-
let fn = "FindProxyForURL(\"" + url + "\",\""+host+"\")"
31-
let proxy = jsEngine.evaluateScript(fn)
32-
result(proxy?.toString())
33-
} catch {
34-
result("DIRECT")
35-
}
36-
} else {
37-
result("DIRECT")
38-
}
24+
let js = args.value(forKey:"js") as! String
25+
let jsEngine:JSContext = JSContext()
26+
jsEngine.evaluateScript(js)
27+
let fn = "FindProxyForURL(\"" + url + "\",\""+host+"\")"
28+
let proxy = jsEngine.evaluateScript(fn)
29+
result(proxy?.toString())
3930
}else{
4031
result("DIRECT")
4132
}

lib/flutter_system_proxy.dart

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'dart:async';
2+
import 'dart:convert';
23
import 'dart:io';
34
import 'package:flutter/services.dart';
45

@@ -32,7 +33,10 @@ class FlutterSystemProxy {
3233
return null;
3334
} else if (Platform.isIOS) {
3435
if (proxySettings["ProxyAutoConfigEnable"] == 1) {
35-
return {"pacEnabled": "true"};
36+
return {
37+
"pacEnabled": "true",
38+
"pacUrl": proxySettings['ProxyAutoConfigURLString']
39+
};
3640
} else {
3741
if (isHttps) {
3842
if (proxySettings['HTTPSEnable'] == 1) {
@@ -65,9 +69,13 @@ class FlutterSystemProxy {
6569
(parsedProxy["host"] as String) +
6670
":" +
6771
(parsedProxy["port"] as String);
68-
} else if (parsedProxy != null && parsedProxy["pacEnabled"] == "true") {
69-
String proxy =
70-
await _channel.invokeMethod("executePAC", {"url": url, "host": host});
72+
} else if (parsedProxy != null &&
73+
parsedProxy["pacEnabled"] == "true" &&
74+
parsedProxy["pacUrl"] != null) {
75+
String pacLocation = parsedProxy["pacUrl"] as String;
76+
String jsContents = await contents(pacLocation);
77+
String proxy = await _channel.invokeMethod(
78+
"executePAC", {"url": url, "host": host, "js": jsContents});
7179
return proxy;
7280
} else {
7381
return HttpClient.findProxyFromEnvironment(Uri.parse(url));
@@ -88,3 +96,15 @@ bool isPort(String? port) {
8896
return false;
8997
}
9098
}
99+
100+
Future<String> contents(String url) async {
101+
HttpClient client = new HttpClient();
102+
var completor = new Completer<String>();
103+
client.findProxy = null;
104+
var request = await client.getUrl(Uri.parse(url));
105+
var response = await request.close();
106+
response.transform(utf8.decoder).listen((contents) {
107+
completor.complete(contents);
108+
});
109+
return completor.future;
110+
}

pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: flutter_system_proxy
22
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.
3-
version: 0.0.1
3+
version: 0.0.2
44
homepage: https://github.com/Rushabhshroff/flutter_system_proxy.git
55

66
environment:
@@ -24,4 +24,4 @@ flutter:
2424
ios:
2525
pluginClass: FlutterSystemProxyPlugin
2626

27-
27+

0 commit comments

Comments
 (0)