Cleanup docs and code of setProxy
This commit is contained in:
parent
34c9279fc5
commit
192fa4c86b
2 changed files with 38 additions and 43 deletions
|
@ -114,27 +114,25 @@ struct Converter<net::ProxyConfig> {
|
||||||
static bool FromV8(v8::Isolate* isolate,
|
static bool FromV8(v8::Isolate* isolate,
|
||||||
v8::Local<v8::Value> val,
|
v8::Local<v8::Value> val,
|
||||||
net::ProxyConfig* out) {
|
net::ProxyConfig* out) {
|
||||||
|
std::string proxy_rules;
|
||||||
|
GURL pac_url;
|
||||||
mate::Dictionary options;
|
mate::Dictionary options;
|
||||||
if (!ConvertFromV8(isolate, val, &options)) {
|
// Fallback to previous API when passed String.
|
||||||
// Fallback to previous api (https://git.io/vuhjj).
|
// https://git.io/vuhjj
|
||||||
std::string proxy;
|
if (ConvertFromV8(isolate, val, &proxy_rules)) {
|
||||||
if (!ConvertFromV8(isolate, val, &proxy))
|
pac_url = GURL(proxy_rules); // Assume it is PAC script if it is URL.
|
||||||
return false;
|
} else if (ConvertFromV8(isolate, val, &options)) {
|
||||||
auto pac_url = GURL(proxy);
|
options.Get("pacScript", &pac_url);
|
||||||
if (pac_url.is_valid()) {
|
options.Get("proxyRules", &proxy_rules);
|
||||||
out->set_pac_url(pac_url);
|
} else {
|
||||||
} else {
|
return false;
|
||||||
out->proxy_rules().ParseFromString(proxy);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GURL pac_url;
|
// pacScript takes precedence over proxyRules.
|
||||||
std::string rules;
|
if (!pac_url.is_empty() && pac_url.is_valid()) {
|
||||||
if (options.Get("pacScript", &pac_url)) {
|
|
||||||
out->set_pac_url(pac_url);
|
out->set_pac_url(pac_url);
|
||||||
} else if (options.Get("proxyRules", &rules)) {
|
} else {
|
||||||
out->proxy_rules().ParseFromString(rules);
|
out->proxy_rules().ParseFromString(proxy_rules);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -186,37 +186,34 @@ Clears the data of web storages.
|
||||||
* `proxyRules` String - Rules indicating which proxies to use.
|
* `proxyRules` String - Rules indicating which proxies to use.
|
||||||
* `callback` Function - Called when operation is done.
|
* `callback` Function - Called when operation is done.
|
||||||
|
|
||||||
|
Sets the proxy settings.
|
||||||
|
|
||||||
When `pacScript` and `proxyRules` are provided together, the `proxyRules`
|
When `pacScript` and `proxyRules` are provided together, the `proxyRules`
|
||||||
option is ignored and `pacScript` configuration is applied.
|
option is ignored and `pacScript` configuration is applied.
|
||||||
|
|
||||||
```
|
The `proxyRules` has to follow the rules bellow:
|
||||||
proxyRules = scheme-proxies[";"<scheme-proxies>]
|
|
||||||
scheme-proxies = [<url-scheme>"="]<proxy-uri-list>
|
|
||||||
url-scheme = "http" | "https" | "ftp" | "socks"
|
|
||||||
proxy-uri-list = <proxy-uri>[","<proxy-uri-list>]
|
|
||||||
proxy-uri = [<proxy-scheme>"://"]<proxy-host>[":"<proxy-port>]
|
|
||||||
|
|
||||||
For example:
|
|
||||||
"http=foopy:80;ftp=foopy2" -- use HTTP proxy "foopy:80" for http://
|
|
||||||
URLs, and HTTP proxy "foopy2:80" for
|
|
||||||
ftp:// URLs.
|
|
||||||
"foopy:80" -- use HTTP proxy "foopy:80" for all URLs.
|
|
||||||
"foopy:80,bar,direct://" -- use HTTP proxy "foopy:80" for all URLs,
|
|
||||||
failing over to "bar" if "foopy:80" is
|
|
||||||
unavailable, and after that using no
|
|
||||||
proxy.
|
|
||||||
"socks4://foopy" -- use SOCKS v4 proxy "foopy:1080" for all
|
|
||||||
URLs.
|
|
||||||
"http=foopy,socks5://bar.com -- use HTTP proxy "foopy" for http URLs,
|
|
||||||
and fail over to the SOCKS5 proxy
|
|
||||||
"bar.com" if "foopy" is unavailable.
|
|
||||||
"http=foopy,direct:// -- use HTTP proxy "foopy" for http URLs,
|
|
||||||
and use no proxy if "foopy" is
|
|
||||||
unavailable.
|
|
||||||
"http=foopy;socks=foopy2 -- use HTTP proxy "foopy" for http URLs,
|
|
||||||
and use socks4://foopy2 for all other
|
|
||||||
URLs.
|
|
||||||
```
|
```
|
||||||
|
proxyRules = schemeProxies[";"<schemeProxies>]
|
||||||
|
schemeProxies = [<urlScheme>"="]<proxyURIList>
|
||||||
|
urlScheme = "http" | "https" | "ftp" | "socks"
|
||||||
|
proxyURIList = <proxyURL>[","<proxyURIList>]
|
||||||
|
proxyURL = [<proxyScheme>"://"]<proxyHost>[":"<proxyPort>]
|
||||||
|
```
|
||||||
|
|
||||||
|
For example:
|
||||||
|
* `http=foopy:80;ftp=foopy2` - Use HTTP proxy `foopy:80` for `http://` URLs, and
|
||||||
|
HTTP proxy `foopy2:80` for `ftp://` URLs.
|
||||||
|
* `foopy:80` - Use HTTP proxy `foopy:80` for all URLs.
|
||||||
|
* `foopy:80,bar,direct://` - Use HTTP proxy `foopy:80` for all URLs, failing
|
||||||
|
over to `bar` if `foopy:80` is unavailable, and after that using no proxy.
|
||||||
|
* `socks4://foopy` - Use SOCKS v4 proxy `foopy:1080` for all URLs.
|
||||||
|
* `http=foopy,socks5://bar.com` - Use HTTP proxy `foopy` for http URLs, and fail
|
||||||
|
over to the SOCKS5 proxy `bar.com` if `foopy` is unavailable.
|
||||||
|
* `http=foopy,direct://` - Use HTTP proxy `foopy` for http URLs, and use no
|
||||||
|
proxy if `foopy` is unavailable.
|
||||||
|
* `http=foopy;socks=foopy2` - Use HTTP proxy `foopy` for http URLs, and use
|
||||||
|
`socks4://foopy2` for all other URLs.
|
||||||
|
|
||||||
### `ses.resolveProxy(url, callback)`
|
### `ses.resolveProxy(url, callback)`
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue