diff --git a/atom/browser/api/atom_api_session.cc b/atom/browser/api/atom_api_session.cc index 379d16ecf857..f71b28c1cb70 100644 --- a/atom/browser/api/atom_api_session.cc +++ b/atom/browser/api/atom_api_session.cc @@ -114,27 +114,25 @@ struct Converter { static bool FromV8(v8::Isolate* isolate, v8::Local val, net::ProxyConfig* out) { + std::string proxy_rules; + GURL pac_url; mate::Dictionary options; - if (!ConvertFromV8(isolate, val, &options)) { - // Fallback to previous api (https://git.io/vuhjj). - std::string proxy; - if (!ConvertFromV8(isolate, val, &proxy)) - return false; - auto pac_url = GURL(proxy); - if (pac_url.is_valid()) { - out->set_pac_url(pac_url); - } else { - out->proxy_rules().ParseFromString(proxy); - } - return true; + // Fallback to previous API when passed String. + // https://git.io/vuhjj + if (ConvertFromV8(isolate, val, &proxy_rules)) { + pac_url = GURL(proxy_rules); // Assume it is PAC script if it is URL. + } else if (ConvertFromV8(isolate, val, &options)) { + options.Get("pacScript", &pac_url); + options.Get("proxyRules", &proxy_rules); + } else { + return false; } - GURL pac_url; - std::string rules; - if (options.Get("pacScript", &pac_url)) { + // pacScript takes precedence over proxyRules. + if (!pac_url.is_empty() && pac_url.is_valid()) { out->set_pac_url(pac_url); - } else if (options.Get("proxyRules", &rules)) { - out->proxy_rules().ParseFromString(rules); + } else { + out->proxy_rules().ParseFromString(proxy_rules); } return true; } diff --git a/docs/api/session.md b/docs/api/session.md index 41d27773f9a1..a8a55b593f27 100644 --- a/docs/api/session.md +++ b/docs/api/session.md @@ -186,37 +186,34 @@ Clears the data of web storages. * `proxyRules` String - Rules indicating which proxies to use. * `callback` Function - Called when operation is done. +Sets the proxy settings. + When `pacScript` and `proxyRules` are provided together, the `proxyRules` option is ignored and `pacScript` configuration is applied. -``` -proxyRules = scheme-proxies[";"] -scheme-proxies = ["="] -url-scheme = "http" | "https" | "ftp" | "socks" -proxy-uri-list = [","] -proxy-uri = ["://"][":"] +The `proxyRules` has to follow the rules bellow: - 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 = ["="] +urlScheme = "http" | "https" | "ftp" | "socks" +proxyURIList = [","] +proxyURL = ["://"][":"] +``` + +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)`