Bug 998372 - part 2 - lift origins out of FindProxyForURL and make origin lookups more efficient; r=jmaher

This commit is contained in:
Nathan Froyd 2014-04-18 12:17:15 -04:00
parent 72d04e8a9a
commit bd4e6c902e
2 changed files with 5 additions and 3 deletions

View File

@ -308,6 +308,9 @@ class Permissions(object):
# 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+.]*)' +
'://' +
'(?:[^/@]*@)?' +
@ -316,7 +319,6 @@ var uriRegex = new RegExp('^([a-z][-a-z0-9+.]*)' +
function FindProxyForURL(url, host)
{
var origins = [%(origins)s];
var matches = uriRegex.exec(url);
if (!matches)
return 'DIRECT';
@ -335,7 +337,7 @@ function FindProxyForURL(url, host)
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';

2
testing/mozbase/mozprofile/tests/permissions.py Normal file → Executable file
View File

@ -123,7 +123,7 @@ http://127.0.0.1:8888 privileged
self.assertEqual(user_prefs[0], ('network.proxy.type', 2))
self.assertEqual(user_prefs[1][0], 'network.proxy.autoconfig_url')
origins_decl = "var origins = ['http://mochi.test:8888', 'http://127.0.0.1:80', 'http://127.0.0.1:8888'];"
origins_decl = "var knownOrigins = (function () { return ['http://mochi.test:8888', 'http://127.0.0.1:80', 'http://127.0.0.1:8888'].reduce"
self.assertTrue(origins_decl in user_prefs[1][1])
proxy_check = ("if (isHttp) return 'PROXY mochi.test:8888';",