Browse Source

Merge pull request #6558 from deepak1556/session_proxy_patch

session: add proxyBypassRules option to setProxy api
Cheng Zhao 8 years ago
parent
commit
fd8cc63ca9
3 changed files with 69 additions and 1 deletions
  1. 3 1
      atom/browser/api/atom_api_session.cc
  2. 39 0
      docs/api/session.md
  3. 27 0
      spec/api-session-spec.js

+ 3 - 1
atom/browser/api/atom_api_session.cc

@@ -133,7 +133,7 @@ struct Converter<net::ProxyConfig> {
   static bool FromV8(v8::Isolate* isolate,
                      v8::Local<v8::Value> 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<net::ProxyConfig> {
     } 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<net::ProxyConfig> {
       out->set_pac_url(pac_url);
     } else {
       out->proxy_rules().ParseFromString(proxy_rules);
+      out->proxy_rules().bypass_rules.ParseFromString(proxy_bypass_rules);
     }
     return true;
   }

+ 39 - 0
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 [ ":" <port> ]`
+
+   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".
+
+*  `<local>`
+
+   Match local addresses. The meaning of `<local>` is whether the
+   host matches one of: "127.0.0.1", "::1", "localhost".
+
 ### `ses.resolveProxy(url, callback)`
 
 * `url` URL

+ 27 - 0
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: '<local>'
+      }
+      session.defaultSession.setProxy(config, function () {
+        session.defaultSession.resolveProxy('http://localhost', function (proxy) {
+          assert.equal(proxy, 'DIRECT')
+          done()
+        })
+      })
+    })
+  })
 })