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:
-
isPlainHostName(host) Returns true if host contains
no dots (".").
-
dnsDomainIs(host, domain) True if domain
is in host.
-
localHostOrDomainIs(host, hostdomain) True if
host is a host or domain contained in hostdomain
-
isResolvable(host) True if host can be resolved to an
IP address
-
isInNet(host, pattern, mask) True if the IP address
or hostname in host is in the network specified by pattern
and mask.
-
dnsResolve(host) host is resolved to an IP address
-
myIpAddress() local IP address
-
dnsDomainLevels(host) Returns the number of dots in
host.
-
shExpMatch(str, shellexp) True if str matches
the shell expression (not regexp) shellexp. E.g.
shExpMatch("a/b/c","*/b/*") is true.
-
weekdayRange(wd1 [, wd2 ][, "GMT"]) True if today
is, or is in the range, of the weekday(s) specified as quoted strings
(SUN|MON|TUE|WED|THU|FRI|SAT)
-
dateRange([day1] [,month1] [,year1]
[,day2] [,month2] [,year2] [,"GMT"]) True if
today is in the range specified. The months must be specified as quoted strings
(JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)
-
timeRange(hour1, minute1, second1, hour2,
minute2, second2 [, "GMT"])
timeRange(hour1, minute1, hour2, minute2
[, "GMT"])
timeRange(hour1, hour2 [, "GMT"])
timeRange(hour [, "GMT"])
-
ProxyConfig.bindings
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: