Abdullah Diab’s Blog

Using curl with Proxy PAC configuration files

curl is an essential tool that most developers use, it will allow you to execute a wide range of HTTP requests from your terminal, it supports using a proxy to execute your requests, but it does not support PAC configuration files.

At my work I have to use a PAC file due to the large list of servers I’d interact with, and many would require me passing through specific proxies. It is a cumbersome process for me to memorize or try every URL I want to request and to identify which proxy to use, that’s why I wrote a simple perl script (yes perl not Python!) to help me with this issue.

Before you use it

  • This script is written with Perl 5.16 in mind I haven’t tested it on other versions, but I suppose it should work properly, please let me know if it doesn’t work for you.
  • It also makes use of the following perl modules: Regexp::Common and HTTP::ProxyPAC.

Download

The script’s gist is here

The script is available under GPLv3.

After downloading the script make sure it is executable:

chmod +x curlp.pl

And edit the file and set the variable $PAC_URI to your PAC URI in line 14.

How to use

You can use the script just like you use curl normally, it will automatically call curl with the appropriate proxy, but PLEASE NOTE this script will accept the URL as its last parameter always, and will pass any parameters that are before the url to curl blindly.

./curlp.pl ....... [URL]