maintain api compatibility
authorRobo <hop2deep@gmail.com>
Mon, 11 Jan 2016 06:54:01 +0000 (12:24 +0530)
committerRobo <hop2deep@gmail.com>
Mon, 11 Jan 2016 06:54:01 +0000 (12:24 +0530)
atom/browser/api/atom_api_session.cc
docs/api/session.md

index 0b2f4f9..379d16e 100644 (file)
@@ -115,14 +115,27 @@ struct Converter<net::ProxyConfig> {
                      v8::Local<v8::Value> val,
                      net::ProxyConfig* out) {
     mate::Dictionary options;
-    if (!ConvertFromV8(isolate, val, &options))
-      return false;
+    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;
+    }
+
     GURL pac_url;
     std::string rules;
-    if (options.Get("pacScript", &pac_url))
+    if (options.Get("pacScript", &pac_url)) {
       out->set_pac_url(pac_url);
-    else if (options.Get("proxyRules", &rules))
+    } else if (options.Get("proxyRules", &rules)) {
       out->proxy_rules().ParseFromString(rules);
+    }
     return true;
   }
 };
index 67dd537..41d2777 100644 (file)
@@ -186,6 +186,9 @@ Clears the data of web storages.
   * `proxyRules` String - Rules indicating which proxies to use.
 * `callback` Function - Called when operation is done.
 
+When `pacScript` and `proxyRules` are provided together, the `proxyRules`
+option is ignored and `pacScript` configuration is applied.
+
 ```
 proxyRules = scheme-proxies[";"<scheme-proxies>]
 scheme-proxies = [<url-scheme>"="]<proxy-uri-list>