diff --git a/atom/browser/api/atom_api_session.cc b/atom/browser/api/atom_api_session.cc index f839490dd..02fafddf9 100644 --- a/atom/browser/api/atom_api_session.cc +++ b/atom/browser/api/atom_api_session.cc @@ -133,7 +133,7 @@ struct Converter { static bool FromV8(v8::Isolate* isolate, v8::Local val, net::ProxyConfig* out) { - std::string proxy_rules; + std::string proxy_rules, proxy_bypass_rules; GURL pac_url; mate::Dictionary options; // Fallback to previous API when passed String. @@ -143,6 +143,7 @@ struct Converter { } else if (ConvertFromV8(isolate, val, &options)) { options.Get("pacScript", &pac_url); options.Get("proxyRules", &proxy_rules); + options.Get("proxyBypassRules", &proxy_bypass_rules); } else { return false; } @@ -152,6 +153,7 @@ struct Converter { out->set_pac_url(pac_url); } else { out->proxy_rules().ParseFromString(proxy_rules); + out->proxy_rules().bypass_rules.ParseFromString(proxy_bypass_rules); } return true; } diff --git a/docs/api/session.md b/docs/api/session.md index 2053a44a5..527effc4d 100644 --- a/docs/api/session.md +++ b/docs/api/session.md @@ -121,6 +121,8 @@ Writes any unwritten DOMStorage data to disk. * `config` Object * `pacScript` String - The URL associated with the PAC file. * `proxyRules` String - Rules indicating which proxies to use. + * `proxyBypassRules` String - Rules indicating which URLs should + bypass the proxy settings. * `callback` Function - Called when operation is done. Sets the proxy settings. @@ -153,6 +155,43 @@ For example: * `http=foopy;socks=foopy2` - Use HTTP proxy `foopy` for http URLs, and use `socks4://foopy2` for all other URLs. +The `proxyBypassRules` is a comma separated list of rules described below: + +* `[ URL_SCHEME "://" ] HOSTNAME_PATTERN [ ":" ]` + + Match all hostnames that match the pattern HOSTNAME_PATTERN. + + Examples: + "foobar.com", "*foobar.com", "*.foobar.com", "*foobar.com:99", + "https://x.*.y.com:99" + + * `"." HOSTNAME_SUFFIX_PATTERN [ ":" PORT ]` + + Match a particular domain suffix. + + Examples: + ".google.com", ".com", "http://.google.com" + +* `[ SCHEME "://" ] IP_LITERAL [ ":" PORT ]` + + Match URLs which are IP address literals. + + Examples: + "127.0.1", "[0:0::1]", "[::1]", "http://[::1]:99" + +* `IP_LITERAL "/" PREFIX_LENGHT_IN_BITS` + + Match any URL that is to an IP literal that falls between the + given range. IP range is specified using CIDR notation. + + Examples: + "192.168.1.1/16", "fefe:13::abc/33". + +* `` + + Match local addresses. The meaning of `` is whether the + host matches one of: "127.0.0.1", "::1", "localhost". + ### `ses.resolveProxy(url, callback)` * `url` URL diff --git a/spec/api-session-spec.js b/spec/api-session-spec.js index 1696fedc4..640cc4455 100644 --- a/spec/api-session-spec.js +++ b/spec/api-session-spec.js @@ -342,4 +342,31 @@ describe('session module', function () { w.loadURL(`${protocolName}://fake-host`) }) }) + + describe('ses.setProxy(options, callback)', function () { + it('allows configuring proxy settings', function (done) { + const config = { + proxyRules: 'http=myproxy:80' + } + session.defaultSession.setProxy(config, function () { + session.defaultSession.resolveProxy('http://localhost', function (proxy) { + assert.equal(proxy, 'PROXY myproxy:80') + done() + }) + }) + }) + + it('allows bypassing proxy settings', function (done) { + const config = { + proxyRules: 'http=myproxy:80', + proxyBypassRules: '' + } + session.defaultSession.setProxy(config, function () { + session.defaultSession.resolveProxy('http://localhost', function (proxy) { + assert.equal(proxy, 'DIRECT') + done() + }) + }) + }) + }) })