PAC file and JavaScript help

Status
Not open for further replies.
i am trying to condense/optimize my PAC file, and need some help. i have an "associative" array where networks and netmasks are specified. i want to loop through the array and if the URL resolves to an IP in one of the array networks, return DIRECT.

what happens is everything returns DIRECT, even though the URL does not resolve to an IP in the array. what am i doing wrong?
Code:
function FindProxyForURL(url,host)
{
        // This is an associative array -- the network and mask are in separate arrays
        // Access to hosts inside the NETWORKS will be sent direct -- unproxied
        var direct_access_nets = new Array();
        var direct_access_mask = new Array();
                direct_access_nets[0] = "10.0.0.0";
                direct_access_mask[0] = "255.0.0.0";
                direct_access_nets[1] = "127.0.0.0";
                direct_access_mask[1] = "255.0.0.0";
                direct_access_nets[2] = "172.16.0.0";
                direct_access_mask[2] = "255.240.0.0";
                direct_access_nets[3] = "192.168.0.0";
                direct_access_mask[3] = "255.255.255.0";

        var primary = "proxy1";
        var secondary = "proxy2";
        var tertiary = "proxy3";
        var quarternary = "proxy4";

        for (var i=0; i<direct_access_nets.length; i++) {
                if (isInNet(dnsResolve(host), direct_access_nets[i], direct_access_mask[i])) return "DIRECT";
        }

        return "PROXY "+primary+":8080; "+"PROXY "+secondary+":8080; "+"PROXY "+tertiary+":8080; "+"PROXY "+quaternary+":8080";
}
 

andrewme

Senator
7,120
Subscriptor
[url=http:/civis/viewtopic.php?p=29624295#p29624295:l17547fk said:
Fristie Blade[/url]":l17547fk]Why does your function have a signature "FindProxyForURL(url,host)" and then never uses the url parameter?

Because that's the signature mandated by the spec. It's possible to make proxy decisions according to host only, so ignoring the "url" parameter is perfectly legal.

Why is the "dnsResolve(host)" inside the loop instead of calculating its value right before the loop and storing it into a variable?

Inefficient, but not an error.
 

krimhorn

Ars Legatus Legionis
39,865
[url=http:/civis/viewtopic.php?p=29631727#p29631727:33o0w7d4 said:
andrewme[/url]":33o0w7d4]
Inefficient, but not an error.
True, but moving it out may make it more clear what's going on in isInNet and be more efficient.

I echo that suggestion to add the isInNet code as it seems to be where the issue lies (well, it's the only place it could lie, actually).
 
[url=http:/civis/viewtopic.php?p=29632467#p29632467:3sil2op2 said:
krimhorn[/url]":3sil2op2]
[url=http:/civis/viewtopic.php?p=29631727#p29631727:3sil2op2 said:
andrewme[/url]":3sil2op2]
Inefficient, but not an error.
True, but moving it out may make it more clear what's going on in isInNet and be more efficient.

I echo that suggestion to add the isInNet code as it seems to be where the issue lies (well, it's the only place it could lie, actually).

Not that they're universally "truth", but http://findproxyforurl.com/misconceptions/ says:

When using multiple DNS dependent PAC functions, a browser will perform a new DNS look-up for the same host with each function.

False. The PAC implementation by all major browsers (Internet Explorer, Firefox, Chrome, and Safari) has not been found to exhibit any unusual behavior when leveraging the DNS system.

If the browser accessed a host accessed recently, the local DNS cache will provide the DNS result to the browser. If a host hasn’t been accessed recently and is not in the DNS cache, the DNS servers configured for the host machine will be asked to provide the DNS result. This will be performed once and the result cached locally.
 

andrewme

Senator
7,120
Subscriptor
[url=http:/civis/viewtopic.php?p=29632467#p29632467:shr9a6wj said:
krimhorn[/url]":shr9a6wj]

I echo that suggestion to add the isInNet code as it seems to be where the issue lies (well, it's the only place it could lie, actually).

isInNet is a built-in function provided by the browser for use by PAC files. It's not something the OP is defining (at least, they shouldn't be). See my "spec" link.
 
Status
Not open for further replies.