You are currently viewing a snapshot of www.mozilla.org taken on April 21, 2008. Most of this content is highly out of date (some pages haven't been updated since the project began in 1998) and exists for historical purposes only. If there are any pages on this archive site that you think should be added back to www.mozilla.org, please file a bug.



Proxy Auto Config in Mozilla

-Gagan Saksena 07/26/00

About this document  INCOMPLETE

This document is obsolete, and remains purely for historical purposes. (See bug 128270)
Comments and feedback are always welcome. A significant section of this document is work in progress and is likely to be updated in future. If I get enough questions to require an FAQ, I will write one.

Here is a quick list of items this document covers--

  1. What is PAC?
  2. Current implementation in Mozilla
  3. Design considerations and notes
  4. Future work/TODO
  5. Known problems
  6. Installing an existing PAC file in Mozilla

  1. What is PAC?
  2. Introduction

    The Proxy Auto Config mechanism is a way to dynamically configure proxies for a given URL based on several factors ranging from URL's domain name to time of the day. Typically for each URL that the client requests, a function is called to check is a proxy is to be used for that URL. Based on the response of this function a proxy setting is used for that URL. Since the implementation of this function is typically (and most importantly historically) been in Javascript, it is very easy to configure this function to fairly well-designed the use of proxies for specific URLs.

    Proxy Auto Config (PAC) has been supported in several versions of the Netscape browser. (Most of the version 3 and above browsers) Here is the original document that describes the Proxy Auto Config file format. Note that since its original implementation in Mozilla/2.0 a significant set of api's for PAC has been deprecated.

    The implementation in Netscape's previous versions of the browser allowed for API calls (predefined functions) like weekdayRange(), dateRange(), etc. These functions are now deprecated. More about this later.

  3. Current implementation in Mozilla
  4. Interfaces and Components

    The current implementation in Mozilla sets up a ProxyAutoConfig component. To read more about components check out this page.TODO

    The PAC in Mozilla is a Javascript component that implements the nsIProxyAutoConfig interface. This interface provide the key function ProxyForURL which decides the proxy to use for a specified URL. The magic of XPCOM allows you to write a new implementation in C++ to replace the existing JS one.

    The nsIProxyAutoConfigUtils interface was originally designed to use and isolate the helper functions which are required for implementing the network helper functions like dnsResolve, isInNet, etc. For now the implementation of this interface is with the DNS service.

    An end-to-end example

  5. Design considerations and notes
  6. The way this whole thing works.
    If available the FindProxyForURL function gets called for each and every URL loaded. This could be a big performance issue if the implementation is extensive.

  7. Future work/TODO
    • Fix known problems.
      Pull PAC off the servers.
      Installation that moves/ports existing PAC files.
      Deprecate functions.
      Native implementations of PACUtils.(deprecated)

  8. Known problems
  9. The problem existing is that currently there is no way to include a JS file in another. The potential solutions- -JS 2.0 could support include files.
    -JS Context could be handed over to the new file.
    -The existing workaround.
    Append the existing PAC file with the raw one provided.
    The exception with dynamically updated (PAC files on server)
    • Multiple return values are ignored. Only the first one is tried. So "PROXY foo;bar; DIRECT" only tries foo. TODO-No bug assigned.
    • Several JS stub functions are no-ops. TODO-No bug assigned.

  10. Installing an existing PAC file in Mozilla
  11. Steps to install a PAC file

    1. If the PAC file is on a remote server then download the PAC file to a local copy.
    2. Copy mozilla/netwerk/base/src/nsProxyAutoConfig.js to mozilla/dist/bin/components (this step may not be needed if the file is already installed there!)
    3. Edit the nsProxyAutoConfig.js file in mozilla/dist/bin/components directory and remove the sample implementation towards the end of the file starting with the line-
      //Sample implementation ...
      
    4. Append your existing PAC file (the one from step 1) to this file.
    5. Go to Edit->Preferences->Advanced->Proxies and select the "Automatic Proxy configuration URL:" radio button. There is no need to type anything in the URL field (that is currently ignored till bug 53080 is fixed)
    6. Restart your browser. You should see a console message that says something like--
      ...Registering Proxy Auto Config (a Javascript component!)
      
    7. Enjoy!