09.26.06
Wrong proxy settings? Write your own .pac!
Moving between home and work, I sometimes have issues with the proxy settings of my web browsers.
Today, I was trying out Eclipse, and while looking at the “what-new” and other tutorial related into, I had problems. The proxy.pac file that work has was making requests for 127.0.0.1 (aka “localhost”) also go through the proxy. Now, 1) I think that’s the wrong setting - if I ask for localhost it should go straight back to me - not to the local proxy and (then be ignored). 2) yes, I could set up the manual proxy settings with the appropriate “ignore proxy for” … addresses, but… i’m a coder at heart, so what I could I do?
Write my own (local) .pac file, and tell my browser to use that of course! :)
// Clinton’s custom proxy files - works at home and at work. // Change the work vars to suit your home/school/work needs // If you have multiple proxy setups at home, double-up the proxy behaviour. function FindProxyForURL(url, host) { var work_ip = “136.186.0.0″; var work_ip_mask = “255.255.0.0″; var work_proxy = “PROXY 136.186.1.14:8000; DIRECT”; // If only hostname specified, local host so go direct if (isPlainHostName(host)) return “DIRECT”; // local host is always direct if(isInNet(dnsResolve(host), “127.0.0.1″,“255.255.255.255″)) return “DIRECT”; // Am I at work? Check for my IP in the work ip range if (isInNet(myIpAddress(),work_ip,work_ip_mask)) { // Connect directly to local work domains if (isInNet(dnsResolve(host), work_ip, work_ip_mask)) return “DIRECT”; // Is this a protocol that needs to be sent to the proxy? var bits = url.split(‘:’,2); // set limit - only need 2 var p = (bits.length==2) ? bits[0] : ‘’; if (p ==‘http’ || p == ‘https’ || p == ‘ftp’ || p == ‘gopher’) return work_proxy; } // if you get to here, you don’t get a proxy return “DIRECT”; }
It’s a quick hack, it works (so far) for me, and ymmv, but if you find it useful as well, that would great. This technique could be (and has been) extended to support ‘ad’ filtering from known URLs as well. There is a shExpMatch(url, “http://ads.somedomain.com/*”) function - I was hoping for regex powers, but alas it just supports “shell expressions” and that ain’t half as fun. :)
Helpful links on PAC files:
* http://en.wikipedia.org/wiki/Proxy_auto-config
* http://wp.netscape.com/eng/mozilla/2.0/relnotes/demo/proxy-live.html
* Firebug http://www.joehewitt.com/software/firebug/ - yes it will tell you about errors in the pac file as well - v.cool.