Difference between revisions of "Proxy PAC"

From Ever changing code
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 example.com don't need a proxy:
   // 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";
   }
   }
  // All other requests go through port 8080 of proxy.example.com.
  // should that fail to respond, go directly to the WWW:
   return "DIRECT";
   return "DIRECT";
}
}
Line 32: Line 27:
// Option 2
// Option 2
function FindProxyForURL(url, host) {
function FindProxyForURL(url, host) {
  // our local URLs from the domains below example.com don't need a proxy:
   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";
   }
   }
  // All other requests go through port 8080 of proxy.example.com.
  // should that fail to respond, go directly to the WWW:
   return "DIRECT";
   return "DIRECT";
}
}
</source>
</source>

Latest revision as of 11: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";
}