- Proxy auto-config
The proxy auto-config file defines how
web browser s and otheruser agent s can automatically choose the appropriateproxy 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 particularproxy server or to connect directly.Multiple specifications provide a fallback when a proxy fails to respond. The browser fetches this PAC file before retrieving other pages. The URL of the PAC file is either configured manually or determined automatically by the
Web Proxy Autodiscovery Protocol .Context
Modern web browsers implement several levels of automation; you can choose the level that is appropriate to your needs. The following methods are commonly implemented:
* Manual proxy selection: Specify a hostname and a port number to be used for all URLs. Most browsers allow you to specify a list of domains (such as localhost) that will bypass this proxy.
* Proxy auto-configuration (PAC): Specify the URL for a PAC file with a JavaScript function that determines the appropriate proxy for each URL. This method is more suitable for laptop users who need several different proxy configurations, or complex corporate setups with many different proxies, and is discussed in this article.
*Web Proxy Autodiscovery Protocol (WPAD): Let the browser guess the location of the PAC file throughDHCP and DNS lookups. This is discussed in a separate article.The PAC File
To use PAC, you publish a PAC file on a Web server and instruct a user agent to utilize it, either by entering the URL in the proxy connection settings of your browser or through the use of the WPAD protocol.
A PAC file is a text file that defines at least one JavaScript function, FindProxyForURL(url, host). By convention, this file is normally named proxy.pac. The WPAD standard uses wpad.dat.
Even though most clients will process the script regardless of the MIME type returned in the HTTP request, for the sake of completeness and to maximize compatibility, you should instruct your web server to declare the MIME type of this file to be either application/x-ns-proxy-autoconfig or application/x-javascript-config.
There is little evidence to favor the use of one MIME type over the other. It would be, however, reasonable to assume that application/x-ns-proxy-autoconfig will be supported in more clients than application/x-javascript-config as it was defined in the original Netscape specification, the latter type coming in to use more recently.
A very simple example of a PAC file is:This function instructs the browser to retrieve all pages through the proxy on port 8080 of the server proxy.foo.com. Should this proxy fail to respond, the browser contacts the WWW directly, without using a proxy.
Here is a more complicated example demonstrating some available JavaScript functions to be used in the FindProxyForURL function:
Limitations
The function dnsResolve (and similar other functions) performs a DNS lookup that can block your browser for a long time if the DNS server does not respond.
Caching of proxy autoconfiguration results by domain name in Microsoft's
Internet Explorer 5.5 or higher limits the flexibility of the PAC standard. In effect, you can choose the proxy based on the domain name, but not on the path of the URL. Alternatively, you need to disable caching of proxy autoconfiguration results by editing the registry. Refer to the article by de Boyne Pollard (listed in#Further_reading ) for more details.It is recommended to always use IP instead of host domain names in isInNet function for compatibilities with other components in Windows which makes use of Internet Explorer PAC settings, such as .NET 2.0 Framework. For example, The current convention is to fail over to direct connection when a PAC file is unavailable.
Further limitations are related to the JavaScript engine on the local machine.
Further reading
External links
* [http://www.microsoft.com/technet/prodtechnol/ie/reskit/6/part6/c26ie6rk.mspx?mfr=true Description of proxy auto-configuration files from Microsoft]
* [http://code.google.com/p/pacparser pacparser] C and Python library to parse PAC files.
* [http://code.google.com/p/pactester Pactester] A tool to test PAC files.
* [http://luno.org/project/proxyvalidator/ proxyvalidator] Test all destination proxies within a PAC file.
* [http://www.schooner.com/~loverso/no-ads/ PAC-file to filter online advertisement]
* [http://www.securemecca.com/pac.html PAC-file to filter bad hosts and pornography]
Wikimedia Foundation. 2010.