Proxy auto-config
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.[src] A PAC file contains a JavaScript function FindProxyForURL(url, host) .[src] This function returns a string with one or more access method specifications.[src] These specifications cause the user agent to use a particular proxy server or to connect directly.[src] Multiple specifications provide a fallback when a proxy fails to respond.[src] The browser fetches this PAC file before requesting other URLs.[src] The URL of the PAC file is either configured manually or determined automatically by the Web Proxy Auto-Discovery Protocol.[src]
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.[src] A PAC file contains a JavaScript function FindProxyForURL(url, host) .[src] This function returns a string with one or more access method specifications.[src] These specifications cause the user agent to use a particular proxy server or to connect directly.[src] Multiple specifications provide a fallback when a proxy fails to respond.[src] The browser fetches this PAC file before requesting other URLs.[src] The URL of the PAC file is either configured manually or determined automatically by the Web Proxy Auto-Discovery Protocol.[src] returnValue = type host,":",port,[{ ";",returnValue }]; type = "DIRECT" | "PROXY" | "SOCKS" | "HTTP" | "HTTPS" | "SOCKS4" | "SOCKS5" host = UTF16String (* ECMA262-compatible UTF16 string *) port = UTF16String (* Digits *) To use it, a PAC file is published to a HTTP server, and client user agents are instructed to use it, either by entering the URL in the proxy connection settings of the browser or through the use of the WPAD protocol.[src] The URL may also reference a local file as for example: file:///etc/proxy.pac .[src] Even though most clients will process the script regardless of the MIME type returned in the HTTP reply, for the sake of completeness and to maximize compatibility, the HTTP server should be configured to declare the MIME type of this file to be either application/x-ns-proxy-autoconfig or application/x-javascript-config .[src] There is little evidence to favor the use of one MIME type over the other.[src] 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 into use more recently.[src] function FindProxyForURL(url, host) { return 'PROXY proxy.example.com:8080; DIRECT'; } This function instructs the browser to retrieve all pages through the proxy on port 8080 of the server proxy.example.com .[src] Should this proxy fail to respond, the browser contacts the Web-site directly, without using a proxy.[src] The latter may fail if firewalls, or other intermediary network devices, reject requests from sources other than the proxy—a common configuration in corporate networks.[src] A more complicated example demonstrates some available JavaScript functions to be used in the FindProxyForURL function: function FindProxyForURL(url, host) { // our local URLs from the domains below example.com don't need a proxy: if (shExpMatch(host, '*.example.com')) { return 'DIRECT'; } // URLs within this network are accessed through // port 8080 on fastproxy.example.com: if (isInNet(host, '10.0.0.0', '255.255.248.0')) { return 'PROXY fastproxy.example.com:8080'; } // All other requests go through port 8080 of proxy.example.com.[src] // should that fail to respond, go directly to the WWW: return 'PROXY proxy.example.com:8080; DIRECT'; } By default, the PROXY keyword means that a proxy corresponding to the protocol of the original request, be it http, https, or ftp, is used.[src] Other supported keyword and proxy types include: SOCKS: Use a SOCKS proxy.[src] HTTP, HTTPS: Introduced in more recent versions of Firefox.[src] Specifies an HTTP(S) proxy.[src] SOCKS4, SOCKS5: Introduced in more recent versions of Firefox.[src] Specifies the SOCKS protocol version.[src] if (isInNet(host, dnsResolve(sampledomain), '255.255.248.0')) {} // .NET 2.0 will resolve proxy properly if (isInNet(host, sampledomain, '255.255.248.0')) {} // .NET 2.0 will not resolve proxy properly The current convention is to fail over to direct connection when a PAC file is unavailable.[src] Shortly after switching between network configurations (e.g.[src] when entering or leaving a VPN), dnsResolve may give outdated results due to DNS caching.[src] For instance, Firefox usually keeps 20 domain entries cached for 60 seconds.[src] This may be configured via the network.dnsCacheEntries and network.dnsCacheExpiration configuration variables.[src] Flushing the system's DNS cache may also help, which can be achieved e.g.[src] in Linux with sudo service dns-clean start or in Windows with ipconfig /flushdns .[src] On Internet Explorer 9, isInNet('localHostName', 'second.ip', '255.255.255.255') returns true and can be used as a workaround.[src] The myIpAddress function assumes that the device has a single IPv4 address.[src] The results are undefined if the device has more than one IPv4 address or has IPv6 addresses.[src] return 'PROXY proxy1.example.com:80; PROXY proxy2.example.com:8080'; The above will try proxy1 first and if unavailable it will then try proxy2.[src]
40 sentences · 40 cited inline · 0 references stored
References
No reference rows published for this article.
Cite this article
MLA
"Proxy auto-config." encyclopegia.org, 2026, https://encyclopegia.org/wiki/proxy-auto-config. Accessed 28 November 2026.
Chicago
"Proxy auto-config." encyclopegia.org. Accessed November 28, 2026. https://encyclopegia.org/wiki/proxy-auto-config.
APA
encyclopegia.org. (2026). Proxy auto-config. Retrieved November 28, 2026, from https://encyclopegia.org/wiki/proxy-auto-config
Accessed November 28, 2026 · CC BY-SA 4.0 · citation page · JSON