1 // Return a single-proxy result, which encodes ALL the arguments that were
2 // passed to FindProxyForURL().
4 function FindProxyForURL(url, host) {
5 if (arguments.length != 2) {
6 throw "Wrong number of arguments passed to FindProxyForURL!";
10 return "PROXY " + makePseudoHost(url + "." + host);
13 // Form a string that kind-of resembles a host. We will replace any
14 // non-alphanumeric character with a dot, then fix up the oddly placed dots.
15 function makePseudoHost(str) {
18 for (var i = 0; i < str.length; ++i) {
19 var c = str.charAt(i);
20 if (!isValidPseudoHostChar(c)) {
21 c = '.'; // Replace unsupported characters with a dot.
24 // Take care not to place multiple adjacent dots,
25 // a dot at the beginning, or a dot at the end.
27 (result.length == 0 ||
28 i == str.length - 1 ||
29 result.charAt(result.length - 1) == '.')) {
37 function isValidPseudoHostChar(c) {
38 if (c >= '0' && c <= '9')
40 if (c >= 'a' && c <= 'z')
42 if (c >= 'A' && c <= 'Z')