Skip to content

Commit b1bb4cc

Browse files
committed
Disabled proxy for fetching PAC
1 parent f06dde4 commit b1bb4cc

File tree

3 files changed

+35
-24
lines changed

3 files changed

+35
-24
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+
}

0 commit comments

Comments
 (0)