Difference between revisions of "Proxy PAC"
Jump to navigation
Jump to search
Line 7: | Line 7: | ||
// Option 1 | // Option 1 | ||
function FindProxyForURL(url, host) { | function FindProxyForURL(url, host) { | ||
// our local URLs from the domains below | // 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")) { | if (shExpMatch(host, "*.foo.acme.com")) { | ||
return "PROXY proxy.acme.com:8123"; | return "PROXY proxy.acme.com:8123"; | ||
} | } | ||
if (shExpMatch(host, "*.foo-dev.acme.com")) { | if (shExpMatch(host, "*.foo-dev.acme.com")) { | ||
return "PROXY proxy.acme.com:8123"; | return "PROXY proxy.acme.com:8123"; | ||
} | } | ||
if (shExpMatch(host, "*.foo-prod.acme.com")) { | if (shExpMatch(host, "*.foo-prod.acme.com")) { | ||
return "PROXY proxy.acme.com:8123"; | return "PROXY proxy.acme.com:8123"; | ||
} | } | ||
if (shExpMatch(host, "*.example.com")) { | if (shExpMatch(host, "*.example.com")) { | ||
return "PROXY proxy.acme.com:8123"; | return "PROXY proxy.acme.com:8123"; | ||
} | } | ||
return "DIRECT"; | return "DIRECT"; | ||
} | } | ||
Line 32: | Line 27: | ||
// Option 2 | // Option 2 | ||
function FindProxyForURL(url, host) { | function FindProxyForURL(url, host) { | ||
if (shExpMatch(host, "*.foo.acme.com") || | if (shExpMatch(host, "*.foo.acme.com") || | ||
shExpMatch(host, "*.foo-dev.acme.com") || | shExpMatch(host, "*.foo-dev.acme.com") || | ||
Line 39: | Line 33: | ||
return "PROXY proxy.acme.com:8123"; | return "PROXY proxy.acme.com:8123"; | ||
} | } | ||
return "DIRECT"; | return "DIRECT"; | ||
} | } | ||
</source> | </source> |
Latest revision as of 10:19, 15 November 2022
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"; }