Proxy PAC
Jump to navigation
Jump to search
Proxy auto-config | Proxy PAC
A proxy auto-config (PAC) file defines how web browsers and other user agents can automatically choose the appropriate proxy server (access method) for fetching a given URL.
A PAC file contains a JavaScript function FindProxyForURL(url, host). This function returns a string with one or more access method specifications. These specifications cause the user agent to use a particular proxy server or to connect directly.
// Option 1
function FindProxyForURL(url, host) {
// our local URLs from the domains below acme.com
// go through a proxy port 8123 of proxy.acme.com.
if (shExpMatch(host, "*.foo.acme.com")) {
return "PROXY proxy.acme.com:8123";
}
if (shExpMatch(host, "*.foo-dev.acme.com")) {
return "PROXY proxy.acme.com:8123";
}
if (shExpMatch(host, "*.foo-prod.acme.com")) {
return "PROXY proxy.acme.com:8123";
}
if (shExpMatch(host, "*.example.com")) {
return "PROXY proxy.acme.com:8123";
}
return "DIRECT";
}
// Option 2
function FindProxyForURL(url, host) {
if (shExpMatch(host, "*.foo.acme.com") ||
shExpMatch(host, "*.foo-dev.acme.com") ||
shExpMatch(host, "*.foo-prod.acme.com") ||
shExpMatch(host, "*.example.com")) {
return "PROXY proxy.acme.com:8123";
}
return "DIRECT";
}