added reverseBypassEnabled in ProxySettings

This commit is contained in:
Lorenzo Pichilli 2022-10-07 08:37:56 +02:00
parent 6d2408de0e
commit 06ef336c28
5 changed files with 32 additions and 3 deletions

View File

@ -84,6 +84,9 @@ public class ProxyManager extends ChannelDelegateImpl {
if (settings.removeImplicitRules != null && settings.removeImplicitRules) {
proxyConfigBuilder.removeImplicitRules();
}
if (settings.reverseBypassEnabled != null && WebViewFeature.isFeatureSupported(WebViewFeature.PROXY_OVERRIDE_REVERSE_BYPASS)) {
proxyConfigBuilder.setReverseBypassEnabled(settings.reverseBypassEnabled);
}
proxyController.setProxyOverride(proxyConfigBuilder.build(), new Executor() {
@Override
public void execute(Runnable command) {

View File

@ -17,6 +17,7 @@ public class ProxySettings implements ISettings<ProxyConfig> {
List<ProxyRuleExt> proxyRules = new ArrayList<>();
Boolean bypassSimpleHostnames = null;
Boolean removeImplicitRules = null;
Boolean reverseBypassEnabled = false;
@NonNull
@Override
@ -51,6 +52,9 @@ public class ProxySettings implements ISettings<ProxyConfig> {
case "removeImplicitRules":
removeImplicitRules = (Boolean) value;
break;
case "reverseBypassEnabled":
reverseBypassEnabled = (Boolean) value;
break;
}
}
@ -70,6 +74,7 @@ public class ProxySettings implements ISettings<ProxyConfig> {
settings.put("proxyRules", proxyRuleMapList);
settings.put("bypassSimpleHostnames", bypassSimpleHostnames);
settings.put("removeImplicitRules", removeImplicitRules);
settings.put("reverseBypassEnabled", reverseBypassEnabled);
return settings;
}
@ -87,6 +92,7 @@ public class ProxySettings implements ISettings<ProxyConfig> {
}
realSettings.put("bypassRules", proxyConfig.getBypassRules());
realSettings.put("proxyRules", proxyRuleMapList);
realSettings.put("reverseBypassEnabled", proxyConfig.isReverseBypassEnabled());
return realSettings;
}
}

View File

@ -2,17 +2,19 @@ package com.pichillilorenzo.flutter_inappwebview.types;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.webkit.ProxyConfig;
import java.util.HashMap;
import java.util.Map;
public class ProxyRuleExt {
@Nullable
@ProxyConfig.ProxyScheme
private String schemeFilter;
@NonNull
private String url;
public ProxyRuleExt(@Nullable String schemeFilter, @NonNull String url) {
public ProxyRuleExt(@Nullable @ProxyConfig.ProxyScheme String schemeFilter, @NonNull String url) {
this.schemeFilter = schemeFilter;
this.url = url;
}

View File

@ -115,12 +115,24 @@ class ProxySettings {
///Set this to `true` to override the default behavior and force localhost and link-local URLs to be sent through the proxy.
bool? removeImplicitRules;
///Reverse the bypass list.
///
///The default value is `false`, in which case all URLs will use proxy settings except the ones in the bypass list, which will be connected to directly instead.
///
///If set to `true`, then only URLs in the bypass list will use these proxy settings, and all other URLs will be connected to directly.
///
///Use [bypassRules] to add bypass rules.
///
///**NOTE**: available only if [WebViewFeature.PROXY_OVERRIDE_REVERSE_BYPASS] feature is supported.
bool reverseBypassEnabled;
ProxySettings(
{this.bypassRules = const [],
this.directs = const [],
this.proxyRules = const [],
this.bypassSimpleHostnames,
this.removeImplicitRules});
this.removeImplicitRules,
this.reverseBypassEnabled = false});
Map<String, dynamic> toMap() {
return {
@ -128,7 +140,8 @@ class ProxySettings {
"directs": directs,
"proxyRules": proxyRules.map((e) => e.toMap()).toList(),
"bypassSimpleHostnames": bypassSimpleHostnames,
"removeImplicitRules": removeImplicitRules
"removeImplicitRules": removeImplicitRules,
"reverseBypassEnabled": reverseBypassEnabled
};
}
@ -141,6 +154,7 @@ class ProxySettings {
.map((e) => ProxyRule.fromMap(e)) as List<ProxyRule>;
settings.bypassSimpleHostnames = map["bypassSimpleHostnames"];
settings.removeImplicitRules = map["removeImplicitRules"];
settings.reverseBypassEnabled = map["reverseBypassEnabled"];
return settings;
}

View File

@ -66,6 +66,10 @@ class WebViewFeature_ {
static const PROXY_OVERRIDE =
const WebViewFeature_._internal("PROXY_OVERRIDE");
///This feature covers [ProxySettings.reverseBypassEnabled].
static const PROXY_OVERRIDE_REVERSE_BYPASS =
const WebViewFeature_._internal("PROXY_OVERRIDE_REVERSE_BYPASS");
///
static const RECEIVE_HTTP_ERROR =
const WebViewFeature_._internal("RECEIVE_HTTP_ERROR");