• May 19, 2024

Automatic Proxy Configuration

Proxy Auto-Configuration (PAC) file - HTTP - MDN Web Docs

Proxy Auto-Configuration (PAC) file – HTTP – MDN Web Docs

A Proxy Auto-Configuration (PAC) file is a JavaScript function that determines whether web browser requests (HTTP, HTTPS, and FTP) go directly to the destination or are forwarded to a web proxy server. The JavaScript function contained in the PAC file defines the function:
function FindProxyForURL(url, host) {
//… }
Syntaxfunction FindProxyForURL(url, host)
The URL being accessed. The path and query components of URLs are stripped. In Chrome (versions 52 to 73), you can disable this by setting PacHttpsUrlStrippingEnabled to false in policy or by launching with the –unsafe-pac-url command-line flag (in Chrome 74, only the flag works, and from 75 onward, there is no way to disable path-stripping; as of Chrome 81, path-stripping does not apply to HTTP URLs, but there is interest in changing this behavior to match HTTPS); in Firefox, the preference is
The hostname extracted from the URL. This is only for convenience; it is the 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.
DescriptionReturns a string describing the configuration. The format of this string is defined in return value format value format
The JavaScript function returns a single string
If the string is null, no proxies should be used
The string can contain any number of the following building blocks, separated by a semicolon:
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
Recent versions of Firefox support as well:
HTTP host:port
HTTPS host:port
The specified HTTPS proxy should be used
SOCKS4 host:port, SOCKS5 host:port
The specified SOCKS server (with the specified SOCK version) should be used
If there are multiple semicolon-separated settings, the left-most setting will be used, until Firefox fails to establish the connection to the proxy. In that case, the next value will be used, etc.
The browser will automatically retry a previously unresponsive proxy after 30 minutes. Additional attempts will continue beginning at one hour, always adding 30 minutes to the elapsed time between attempts.
If all proxies are down, and there was no DIRECT option specified, the browser will ask if proxies should be temporarily ignored, and direct connections attempted. After 20 minutes, the browser will ask if proxies should be retried, asking again after an additional 40 minutes. Queries will continue, always adding 20 minutes to the elapsed time between queries.
Primary proxy is w3proxy:8080; if that goes down start using mozilla:8081 until the primary proxy comes up again.
Same as above, but if both proxies go down, automatically start making direct connections. (In the first example above, Netscape will ask user confirmation about making direct connections; in this case, there is no user intervention. )
PROXY; SOCKS socks:1080
Use SOCKS if the primary proxy goes down.
The auto-config file should be saved to a file with a filename extension:
And the MIME type should be set to:
Next, you should configure your server to map the filename extension to the MIME type.
The JavaScript function should always be saved to a file by itself but not be embedded in a HTML file or any other file.
The examples at the end of this document are complete. There is no additional syntax needed to save it into a file and use it. (Of course, the JavaScripts must be edited to reflect your site’s domain name and/or subnets. )
Predefined functions and environmentThese functions can be used in building the PAC file:
Hostname based conditions
Related utility functions
URL/hostname based conditions
Time based conditions
Logging utility
There was one associative array (object) already defined, because at the time JavaScript code was unable to define it by itself:
Note: pactester (part of the pacparser package) was used to test the following syntax examples.
The PAC file is named
Command line: pactester -p ~/pacparser-master/tests/ -u (passes the host parameter and the url parameter)
The hostname from the URL (excluding port number).
True if and only if there is no domain name in the hostname (no dots).
isPlainHostName(“) // false
isPlainHostName(“www”) // true
dnsDomainIs(host, domain)
Is the hostname from the URL.
Is the domain name to test the hostname against.
Returns true if and only if the domain of hostname matches.
dnsDomainIs(“, “. “) // true
dnsDomainIs(“www”, “. “) // false
localHostOrDomainIs(host, hostdom)
The hostname from the URL.
Fully qualified hostname to match against.
Is true if the hostname matches exactly the specified hostname, or if there is no domain name part in the hostname, but the unqualified hostname matches.
localHostOrDomainIs(“, “) // true (exact match)
localHostOrDomainIs(“www”, “) // true (hostname match, domain not specified)
localHostOrDomainIs(“, “) // false (domain name mismatch)
localHostOrDomainIs(“”, “) // false (hostname mismatch)
is the hostname from the URL.
Tries to resolve the hostname. Returns true if succeeds.
isResolvable(“) // true
isInNet(host, pattern, mask)
a DNS hostname, or IP address. If a hostname is passed, it will be resolved into an IP address by this function.
an IP address pattern in the dot-separated format.
mask for the IP address pattern informing which parts of the IP address should be matched against. 0 means ignore, 255 means match.
True if and only if the IP address of the host matches the specified IP address pattern.
Pattern and mask specification is done the same way as for SOCKS configuration.
function alert_eval(str) { alert(str + ‘ is ‘ + eval(str))}
alert_eval(‘isInNet(host, “63. 245. 213. 24”, “255. 255. 255”)’)
// “PAC-alert: isInNet(host, “63. 255″) is true”}
hostname to resolve.
Resolves the given DNS hostname into an IP address, and returns it in the dot-separated format as a string.
dnsResolve(“); // returns the string “104. 16. 41. 2”
Any dotted address such as an IP address or mask.
Concatenates the four dot-separated bytes into one 4-byte word and converts it to decimal.
convert_addr(“104. 2”); // returns the decimal number 1745889538
Return value
Returns the server IP address of the machine Firefox is running on, as a string in the dot-separated integer format.
Warning: myIpAddress() returns the same IP address as the server address returned by nslookup localhost on a Linux machine. It does not return the public IP address.
myIpAddress() //returns the string “127. 0. 1. 1” if you were running Firefox on that localhost
Returns the number (integer) of DNS domain levels (number of dots) in the hostname.
dnsDomainLevels(“www”); // 0
dnsDomainLevels(“”); // 1
dnsDomainLevels(“); // 2
is any string to compare (e. g. the URL, or the hostname).
is a shell expression to compare against.
Returns true if the string matches the specified shell glob expression.
Support for particular glob expression syntax varies across browsers:
* (match any number of characters) and? (match one character) are always supported,
while [characters] and [^characters] are additionally supported by some implementations (including Firefox).
Note: If supported by the client, JavaScript regular expressions typically provide a more powerful and consistent way to pattern-match URLs (and other strings).
shExpMatch(“, “*/ari/*”); // returns true
shExpMatch(“, “*/ari/*”); // returns false
weekdayRange(wd1, wd2, [gmt])
Note: (Before Firefox 49) wd1 must be less than wd2 if you want the function to evaluate these parameters as a range. See the warning below.
wd1 and wd2
One of the ordered weekday strings: “SUN”, “MON”, “TUE”, “WED”, “THU”, “FRI”, “SAT”
Is either the string “GMT” or is left out.
Only the first parameter is mandatory. Either the second, the third, or both may be left out.
If only one parameter is present, the function returns a value of true on the weekday that the parameter represents. If the string “GMT” is specified as a second parameter, times are taken to be in GMT. Otherwise, they are assumed to be in the local timezone.
If both wd1 and wd1 are defined, the condition is true if the current weekday is in between those two ordered weekdays. Bounds are inclusive, but the bounds are ordered. If the “GMT” parameter is specified, times are taken to be in GMT. Otherwise, the local timezone is used.
Warning: The order of the days matters.
Before Firefox 49, weekdayRange(“SUN”, “SAT”) will always evaluate to true.
Now weekdayRange(“WED”, “SUN”) will only evaluate to true
if the current day is Wednesday or Sunday.
weekdayRange(“MON”, “FRI”); // returns true Monday through Friday (local timezone)
weekdayRange(“MON”, “FRI”, “GMT”); // returns true Monday through Friday (GMT timezone)
weekdayRange(“SAT”); // returns true on Saturdays local time
weekdayRange(“SAT”, “GMT”); // returns true on Saturdays GMT time
weekdayRange(“FRI”, “MON”); // returns true Friday and Monday only (note, order does matter! )
dateRange( | | , [gmt]) // ambiguity is resolved by assuming year is greater than 31
dateRange(, , [gmt])
dateRange(, , [gmt])
dateRange(, , [gmt])
dateRange(, , , , [gmt])
dateRange(, , , , [gmt])
dateRange(, , , , , , [gmt])
Note: (Before Firefox 49) day1 must be less than day2, month1 must be less than month2, and year1 must be less than year2 if you want the function to evaluate these parameters as a range. See the warning below.
Is the ordered day of the month between 1 and 31 (as an integer).
Is one of the ordered month strings below.
Is the ordered full year integer number. For example, 2016 (not 16).
Is either the string “GMT”, which makes time comparison occur in GMT timezone, or is left out. If left unspecified, times are taken to be in the local timezone.
If only a single value is specified (from each category: day, month, year), the function returns a true value only on days that match that specification. If both values are specified, the result is true between those times, including bounds, but the bounds are ordered.
Warning: The order of the days, months, and years matter; Before Firefox 49, dateRange(“JAN”, “DEC”) will always evaluate to true. Now dateRange(“DEC”, “JAN”) will only evaluate true if the current month is December or January.
dateRange(1); // returns true on the first day of each month, local timezone
dateRange(1, “GMT”) // returns true on the first day of each month, GMT timezone
dateRange(1, 15); // returns true on the first half of each month
dateRange(24, “DEC”); // returns true on 24th of December each year
dateRange(“JAN”, “MAR”); // returns true on the first quarter of the year
dateRange(1, “JUN”, 15, “AUG”);
// returns true from June 1st until August 15th, each year
// (including June 1st and August 15th)
dateRange(1, “JUN”, 1995, 15, “AUG”, 1995);
// returns true from June 1st, 1995, until August 15th, same year
dateRange(“OCT”, 1995, “MAR”, 1996);
// returns true from October 1995 until March 1996
// (including the entire month of October 1995 and March 1996)
// returns true during the entire year of 1995
dateRange(1995, 1997);
// returns true from beginning of year 1995 until the end of year 1997
// The full range of expansions is analogous to dateRange.
timeRange(, , , , , , [gmt])
Note: (Before Firefox 49) the category hour1, min1, sec1 must be less than the category hour2, min2, sec2 if you want the function to evaluate these parameters as a range. See the warning below.
Is the hour from 0 to 23. (0 is midnight, 23 is 11 pm. )
Minutes from 0 to 59.
Seconds from 0 to 59.
Either the string “GMT” for GMT timezone, or not specified, for local timezone.
If only a single value is specified (from each category: hour, minute, second), the function returns a true value only at times that match that specification. If both values are specified, the result is true between those times, including bounds, but the bounds are ordered.
Warning: The order of the hour, minute, second matter; Before Firefox 49, timeRange(0, 23) will always evaluate to true. Now timeRange(23, 0) will only evaluate true if the current hour is 23:00 or midnight.
timerange(12); // returns true from noon to 1pm
timerange(12, 13); // returns true from noon to 1pm
timerange(12, “GMT”); // returns true from noon to 1pm, in GMT timezone
timerange(9, 17); // returns true from 9am to 5pm
timerange(8, 30, 17, 00); // returns true from 8:30am to 5:00pm
timerange(0, 0, 0, 0, 0, 30); // returns true between midnight and 30 seconds past midnight
The string to log
Logs the message in the browser console.
alert(host + ” = ” + dnsResolve(host)); // logs the host name and its IP address
alert(“Error: shouldn’t reach this clause. “); // log a simple message
Example 1Use proxy for everything except local hostsNote: Since all of the examples that follow are very specific, they have not been tested.
All hosts which aren’t fully qualified, or the ones that are in local domain, will be connected to directly. Everything else will go through If the proxy goes down, connections become direct automatically:
if (isPlainHostName(host) || dnsDomainIs(host, “. “)) {
return “DIRECT”;} else {
return “PROXY; DIRECT”;}}
Note: This is the simplest and most efficient autoconfig file for cases where there’s only one proxy. Example 2As above, but use proxy for local servers which are outside the firewallIf there are hosts (such as the main Web server) that belong to the local domain but are outside the firewall and are only reachable through the proxy server, those exceptions can be handled using the localHostOrDomainIs() function:
if (
(isPlainHostName(host) || dnsDomainIs(host, “. “)) &&! localHostOrDomainIs(host, “) &&! localHostOrDomainIs(host, “”)) {
The above example will use the proxy for everything except local hosts in the domain, with the further exception that hosts and will go through the proxy.
Note: The order of the above exceptions for efficiency: localHostOrDomainIs() functions only get executed for URLs that are in local domain, not for every URL. Be careful to note the parentheses around the or expression before the and expression to achieve the above-mentioned efficient behavior. Example 3Use proxy only if cannot resolve hostThis example will work in an environment where the internal DNS server is set up so that it can only resolve internal host names, and the goal is to use a proxy only for hosts that aren’t resolvable:
if (isResolvable(host))
return “DIRECT”;
return “PROXY “;}
The above requires consulting the DNS every time; it can be grouped intelligently with other rules so that DNS is consulted only if other rules do not yield a result:
isPlainHostName(host) ||
dnsDomainIs(host, “. “) ||
isResolvable(host)) {
return “PROXY “;}}
Example 4Subnet based decisionsIn this example all of the hosts in a given subnet are connected-to directly, others are connected through the proxy:
if (isInNet(host, “198. 95. 0”, “255. 0”))
Again, use of the DNS server in the above can be minimized by adding redundant rules in the beginning:
isInNet(host, “198. 0”)) {
Example 5Load balancing/routing based on URL patternsThis example is more sophisticated. There are four (4) proxy servers; one of them is a hot stand-by for all of the other ones, so if any of the remaining three goes down the fourth one will take over. Furthermore, the three remaining proxy servers share the load based on URL patterns, which makes their caching more effective (there is only one copy of any document on the three servers – as opposed to one copy on each of them). The load is distributed like this:
all other domains
hot stand-by
All local accesses are desired to be direct. All proxy servers run on the port 8080 (they don’t need to, you can just change your port but remember to modify your configuations on both side). Note how strings can be concatenated with the + operator in JavaScript.
if (isPlainHostName(host) || dnsDomainIs(host, “. “))
else if (shExpMatch(host, “*”))
return “PROXY; ” +
“PROXY “;}
Example 6Setting a proxy for a specific protocolMost of the standard JavaScript functionality is available for use in the FindProxyForURL() function. As an example, to set different proxies based on the protocol the startsWith() function can be used:
if (artsWith(“:”))
return “PROXY “;
else if (artsWith(“ftp:”))
else if (artsWith(“gopher:”))
else if (artsWith(“:”) || artsWith(“snews:”))
return “DIRECT”;}
Note: The same can be accomplished using the shExpMatch() function described earlier.
For example:
if (shExpMatch(url, “:*”)) {
Note: The autoconfig file can be output by a CGI script. This is useful, for example, when making the autoconfig file act differently based on the client IP address (the REMOTE_ADDR environment variable in CGI).
Usage of isInNet(), isResolvable() and dnsResolve() functions should be carefully considered, as they require the DNS server to be consulted. All the other autoconfig-related functions are mere string-matching functions that don’t require the use of a DNS server. If a proxy is used, the proxy will perform its DNS lookup which would double the impact on the DNS server. Most of the time these functions are not necessary to achieve the desired result.
History and implementationProxy auto-config was introduced into Netscape Navigator 2. 0 in the late 1990s, at the same time when JavaScript was introduced. Open-sourcing Netscape eventually lead to Firefox itself.
The most “original” implementation of PAC and its JavaScript libraries is, therefore, found in early versions of Firefox. These utilities are found in many other open-source systems including Chromium. Firefox later integrated the file into as a C++ string literal. To extract it into its own file, it suffices to copy the chunk into JavaScript with a directive to print it.
Microsoft in general made its own implementation. There used to be some problems with their libraries, but most are resolved by now. They have defined some new “Ex” suffixed functions around the address handling parts to support IPv6. The feature is supported by Chromium, but not yet by Firefox (bugzilla #558253).
Proxy Auto-Configuration URL - ProxyMesh Knowledge Base

Proxy Auto-Configuration URL – ProxyMesh Knowledge Base

One of the easiest ways to change your IP address with a proxy server is by using a proxy auto-configuration URL in your web browser. A proxy auto-configuration URL tells your browser when to use a proxy server, and what proxy server hostname and port to use.
How does a Proxy Auto-Configuration URL Work?
A proxy auto-configuration URL instructs your web browser to download a javascript PAC file, normally called, which contains at least one javascript function called FindProxyForURL.
Most of the time, this function simply tells your browser to always use a specific proxy server hostname and port for all requests. But the function can also restrict proxy usage based on the request. For example, a proxy server might only support HTTP requests, but not HTTPS requests.
In that case, the function would examine the request, and if it’s for a HTTPS URL, it would tell the browser to skip the proxy and go directly to the site. However, if the request is for a normal HTTP URL, then the proxy would be used.
ProxyMesh supports both HTTP requests and HTTPS requests, and so the auto-configuration function will work as both a proxy server and a HTTPS proxy server, but will ignore any non-HTTP requests.
How do I use it with an Authenticated Proxy Server?
Because proxy auto-configuration URLs do not support specifying proxy usernames and password (and for good reason, because it would be a security risk), you must use IP address authentication.
Once your IP is registered with the proxy server, then the proxy auto-config will handle the rest, by specifying the proxy server hostname and port for each request.
How do I set up Automatic Proxy Configuration?
First, you need a proxy auto-config URL to use. ProxyMesh provides all subscribers with this URL in the account dashboard, which you can find after you signup for ProxyMesh.
Once you have a URL to auto-config the proxy, you must go into your browser’s proxy or network settings and look for a setting such as Automatic proxy configuration, Autoconfiguration URL, Automatic proxy configuration URL, or PAC File URL, and then copy/paste the URL.
Once you save this URL in the settings, your browser will be using the automatic proxy configuration for all future requests.
How do I create a PAC file if I’ll be using more than one proxy?
On the dashboard, the files shown in the Auto-Config URL column are for only 1 proxy each, whereas Make Custom Pac File can combine multiple proxies. Use the Make Custom PAC File link on your dashboard to create a file that will randomly choose from multiple proxies for each request.
Before following this link, make sure you’ve selected all of the proxy checkboxes that you want access to from the proxy list on the Dashboard. You can modify your access here:
You need to have at least a 20 plan, so that more than one server will be available for selection.
The maximum number of proxies you can check depends upon your plan. Proxies that you do not have access to are disabled.
Use the Make Custom PAC File link to access the screen listing all the proxies you selected on your dashboard.
These are unchecked on the Make Custom PAC File screen.
On this screen, select only the proxies that you want to include in your file.
Then click the Make PAC button. The system will return a message that shows the resulting file near the bottom of the page.
For example: “Here is a link to your PAC file:
A filename takes the names of the servers listed in the file, e. g.,
To return to the dashboard, click the Back button or click the Dashboard link on the ribbon.
Further Information
For more about
files, please see
Advantages of a Proxy Auto-Configuration (PAC) File on our blog site,
Still need help?
Contact Us
Last updated on September 30, 2021
What are HTTP Proxy Settings? - Apple Support Communities

What are HTTP Proxy Settings? – Apple Support Communities

Looks like no one’s replied in a while.
To start the conversation again, simply ask a new question.
I happened to check the wi-fi settings on my iPhone and noticed that it says, at the bottom of the page, “HTTP Proxy, ” and has what appears to be buttons that state “Off, ” “Manual, ” and “Automatic. ”
In layperson’s terms:
1) What is “HTTP Proxy” as it relates to the iPhone?
2) What is the difference between the three settings?
3) Is one setting more “secure” than another?
4) What are the benefits and detriments of choosing one setting over another?
Thanks in advance.
iMac * MacBook Air * iPhone3G
Posted on Sep 8, 2009 7:30 PM
User profile for user:
What are HTTP Proxy Settings?

Frequently Asked Questions about automatic proxy configuration

What is automatic proxy configuration URL?

A proxy auto-configuration URL instructs your web browser to download a javascript PAC file, normally called proxy. … Most of the time, this function simply tells your browser to always use a specific proxy server hostname and port for all requests.Jul 31, 2021

How do I set automatic proxy settings?

To set a proxy using an automatic configuration script, follow these steps:Open Settings.Click Network & Internet. … Click Proxy. … In the Automatic Proxy Setup section, set the Use Setup Script switch to On.Enter the script address as it was given to you; then click Save.Close Settings.

Should configure proxy be off or automatic?

You really shouldn’t have to worry about these settings. It should be set to off if you don’t know what it does. 1) HTTP Proxy is basically a webaddress you type in to your companies proxy server so you can access the internet.Sep 8, 2009

Leave a Reply

Your email address will not be published. Required fields are marked *