Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have the following .pac file:

function FindProxyForURL(url, host)
{
    return "PROXY proxy.example.com:8080; DIRECT;";
}

I'm using FoxyProxy with Firefox 13 and I was expecting it to fall back to DIRECT if the given proxy isn't available. Instead, I get the message Firefox is configured to use a proxy server that can't be found. Are my expectations misplaced? Is there any way to get it to behave as I would like?

share|improve this question

1 Answer 1

You should tell it explicitly to go DIRECT.

The best way to control this is to detect what network you are on. Here is an example proxy.pac that is little more complex:

function FindProxyForURL(url, host) {
    // Variables
    var proxy_LAN1 = "PROXY 10.61.9.200:8080; DIRECT;"; 
    var LAN1_addr_ip4 = "10.97.100.0"; 
    var LAN1_addr_ip6 = "fe80::b892:6a74:9635:*"; // Needed for FF/TB (Mozilla)
    var proxy_no = "DIRECT";
    var alert_done = 99;

    //alert("My Addr: " + myIpAddress() + "\nURL: " + url + "\nHost: " + host);

    // If address is local, always go direct
    if( isPlainHostName(host) ) {
        //alert("Local address so no proxy");
        return proxy_no;
    }

    // Proxy if PC is on LAN1
    if (isInNet(myIpAddress(), LAN1_addr_ip4, "255.255.255.0") || shExpMatch(myIpAddress(), LAN1_addr_ip6) ) {
        //alert("LAN1 address & proxy");
        return proxy_LAN1;
    }

    // Default to a direct connection
    // alert("Default proxy (none)");
    return proxy_no;
}

/*
NOTES:
    Use alert("xxx") to find out what is happening. IE displays a pop-up, FF/TB use the error console
    Can have multiple proxies to try. Separate each with ;
    For local pac files, IE requires "file://c:\proxy.pac", FF/TB require file:///c:\proxy.pac" (extra /)
    FF/TB - myIpAddress() returns an IPv6 rather than IPv4 address for Vista and Win7 so isInNet() doesn't work!
FUNCTIONS:
    alert(text)
    isPlainHostName(host)
    shExpMatch(lookup, match)
    isInNet(address, lookup.address, netmask)
    myIpAddress()
    dnsDomainIs(host, ".foobar")
EXAMPLES:
    if (shExpMatch(url, "http://192.168.1.100*")) { return proxy_no; }
    if (isInNet(myIpAddress(), "192.168.1.0", "255.255.255.0"))
*/

As you can see, this tries to detect if we are on a specific network and only sets the proxy if that is true.

share|improve this answer
    
I think the question was more related to availability, i.e. if the proxy server goes down. It is not possible to achieve this by differentiating the subnet. –  flixfe Oct 28 '12 at 5:42
    
Ah, I don't think this is how proxy.pac files work. Generally you should always have the same proxy address for the same network. You should make sure your proxies are resilient so that, if one fails, there are others to take up the load otherwise you are putting the whole network at risk. That is why the proxy.pac file focuses on understanding what network you are on. The other problem is that IE at least only checks the proxy for a specific URL once per session. –  Julian Knight Nov 3 '12 at 21:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.