WPAD (Web Proxy Auto Discovery)

WPAD.DAT is a Javascript program to automatically configure proxy servers on a per-URL basis.

Apparently uses the format of the Netscape PAC (Proxy Auto Config) file. The proxy autoconfig file is written in JavaScript. The file must define the function:

        function FindProxyForURL(url, host)
        {
            ...
        }

which will be called by the Navigator in the following way for every URL that is retrieved by it:

        ret = FindProxyForURL(url, host);

where:

url
the full URL being accessed.
host
the hostname extracted from the URL. This is only for convenience, it is the exact same string as between :// and the first : or / after that. The port number is not included in this parameter. It can be extracted from the URL when necessary.
ret
(the return value) a string describing the configuration. The format of this string is as follows:
null
If the string is null, no proxies should be used.
DIRECT
Connections should be made directly, without any proxies.
PROXY host:port
The specified proxy should be used.
SOCKS host:port
The specified SOCKS server should be used.

If there are multiple semicolon-separated settings, the left-most setting will be used, until the browser fails to establish the connection to the proxy. In that case the next value will be used, etc.

In the definition of the function, some predefined functions can be called:

Here is an example that hopes to show why this can be useful. In a large organizatoin running proxy servers for all web access, this script distributes load between 4 proxy servers. One for all .com request, one for .edu requests, another for all other requests and a fourth which is used if any of the first 3 fail to respond.

    function FindProxyForURL(url, host)
    {
        if (isPlainHostName(host) || dnsDomainIs(host, ".mydomain.com"))
            return "DIRECT";
        else if (shExpMatch(host, "*.com"))
            return "PROXY proxy1.mydomain.com:8080; " +
                   "PROXY proxy4.mydomain.com:8080";
        else if (shExpMatch(host, "*.edu"))
            return "PROXY proxy2.mydomain.com:8080; " +
                   "PROXY proxy4.mydomain.com:8080";
        else
            return "PROXY proxy3.mydomain.com:8080; " +
                   "PROXY proxy4.mydomain.com:8080";
    }

See also: