Bug 998372 - part 2 - lift origins out of FindProxyForURL and make origin lookups more efficient; r=jmaher
authorNathan Froyd <froydnj@mozilla.com>
Fri, 18 Apr 2014 12:17:15 -0400
changeset 179932 0a42f8424ccba8d77bdd777d84d62e3311164a13
parent 179931 005a3405219cf1595cf2ada6c128ed1d17efdbfc
child 179933 4029dbea3291edd556186b6a6ae49a56a2922552
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewersjmaher
bugs998372
milestone31.0a1
Bug 998372 - part 2 - lift origins out of FindProxyForURL and make origin lookups more efficient; r=jmaher
testing/mozbase/mozprofile/mozprofile/permissions.py
--- a/testing/mozbase/mozprofile/mozprofile/permissions.py
+++ b/testing/mozbase/mozprofile/mozprofile/permissions.py
@@ -303,25 +303,27 @@ class Permissions(object):
         if isinstance(user_proxy, dict):
             proxy.update(user_proxy)
 
         # TODO: this should live in a template!
         # TODO: So changing the 5th line of the regex below from (\\\\\\\\d+)
         # to (\\\\d+) makes this code work. Not sure why there would be this
         # difference between automation.py.in and this file.
         pacURL = """data:text/plain,
+var knownOrigins = (function () {
+  return [%(origins)s].reduce(function(t, h) { t[h] = true; return t; }, {})
+})();
 var uriRegex = new RegExp('^([a-z][-a-z0-9+.]*)' +
                           '://' +
                           '(?:[^/@]*@)?' +
                           '(.*?)' +
                           '(?::(\\\\d+))?/');
 
 function FindProxyForURL(url, host)
 {
-  var origins = [%(origins)s];
   var matches = uriRegex.exec(url);
   if (!matches)
     return 'DIRECT';
   var isHttp = matches[1] == 'http';
   var isHttps = matches[1] == 'https';
   var isWebSocket = matches[1] == 'ws';
   var isWebSocketSSL = matches[1] == 'wss';
   if (!matches[3])
@@ -330,17 +332,17 @@ function FindProxyForURL(url, host)
     if (isHttps | isWebSocketSSL) matches[3] = '443';
   }
   if (isWebSocket)
     matches[1] = 'http';
   if (isWebSocketSSL)
     matches[1] = 'https';
 
   var origin = matches[1] + '://' + matches[2] + ':' + matches[3];
-  if (origins.indexOf(origin) < 0)
+  if (!(origin in knownOrigins))
     return 'DIRECT';
   if (isHttp) return 'PROXY %(remote)s:%(http)s';
   if (isHttps) return 'PROXY %(remote)s:%(https)s';
   if (isWebSocket) return 'PROXY %(remote)s:%(ws)s';
   if (isWebSocketSSL) return 'PROXY %(remote)s:%(wss)s';
   return 'DIRECT';
 }""" % proxy
         pacURL = "".join(pacURL.splitlines())