Proxy autoconfiguration

2008/04/15 by Lassi A. Liikkanen

Custom proxy.pac - creating and debugging

This page provides a simple guide and an example of a customized proxy autoconfiguration file.

Proxy autoconfiguration is almost an ancient feature first introduced to Netscape Navigator in late 90's. Proxy autoconfiguration file, or proxy.pac, is a file that the browser users to determine how a URL is retrieved, directly or through a proxy server. The PAC is basically a script written in JavaScript and run by the browser at every request for a URL. However, there are few differences to other kinds of JavaScript you normally use, which affect how use and debug the file:

  • Special set of functions are available for the execution of the proxy.pac
  • Execution of proxy.pac does not support all features of Javascript
  • Different browsers have different implementations of proxy.pac execution

The consequence is that proxy.pac is bit difficult to debug. I myself use Firefox's error console for testing.

Example

Example of my proxy.pac customized for mobile use across networks and two different proxy servers, each of which can be alternatively accessed by a SSH tunnel connection.

function FindProxyForURL(url, host) {
	/*
	This script determines the proxy based on following conditions:

	a) Few common exception URL which can't be accessed without proxy
	b) The network currently connected to
	c) The address being visited

	because the PAC syntax is not strict javascript, ELSEIF and ELSE structures are not used here
	*/


	// Exception URL::s
if (
	isPlainHostName(host) ||
	shExpMatch(url, 'https://gateway-wlan.fi/*')
	)
	{ return 'DIRECT'; }


// at home
if (isInNet(myIpAddress(), '10.10.10.0', '255.255.255.0'))
	{
	if (dnsDomainIs(host, 'tkk.fi') || dnsDomainIs(host, 'hut.fi'))
		{ return 'PROXY localhost:89; DIRECT'; }

	else if (shExpMatch(url, 'http://web.ebscohost.com/bsi*'))
		{ return 'PROXY localhost:89; DIRECT';}

	return 'PROXY localhost:88; DIRECT';
	}

// at working place, three c level networks
if (
isInNet(myIpAddress(), '128.214.115.0', '255.255.255.0') ||
isInNet(myIpAddress(), '128.214.114.0', '255.255.255.0') ||
isInNet(myIpAddress(), '128.214.114.0', '255.255.255.0') )
	{

	if (dnsDomainIs(host, 'tkk.fi') || dnsDomainIs(host, 'hut.fi')
	|| shExpMatch(url, 'http://web.ebscohost.com/bsi*'))
		{ return 'PROXY wwwproxy.hut.fi:80; DIRECT'; }

	return 'PROXY scan-proxy.helsinki.fi:8080; DIRECT';
	}

// We're somewhere else, 3g, wifi, etc.
if (
	dnsDomainIs(host, 'tkk.fi') || dnsDomainIs(host, 'hut.fi')
	|| shExpMatch(url, 'http://web.ebscohost.com/bsi*')
	)
		{ return 'PROXY localhost:89; DIRECT'; }

return 'PROXY localhost:88; DIRECT';
}

References

http://homepages.tesco.net/J.deBoynePollard/FGA/web-browser-auto-proxy-configuration.html
Resilion proxy.pac syntax

Keywords: [computers] , [www-techniques] Document's status: Ok (Document dates explained)

This document created: 2008/04/15
Modified: 2008/04/15
Published: 2008/04/15


This document's permanent URI (linking):
http://iki.fi/lassial/guides/computers/080415-proxy_autoconfiguration

© Lassi A. Liikkanen 2008 - 2016. All rights reserved.
^Top of the Page^

*Change layout:
Printable printable
Large text

Myydään:

@lassial Twitter feed: