curl with Proxy auto-config (PAC) files
#!/usr/bin/env perl | |
# This work is licensed under the GNU Public License (GPLv3). | |
# To view a copy of this license, visit http://www.gnu.org/copyleft/gpl.html | |
# To read more about this script go to: http://mpcabd.xyz/using-curl-with-proxy-pac-configuration-files/ | |
use strict; | |
use warnings; | |
use HTTP::ProxyPAC; | |
use Regexp::Common qw /URI/; | |
my $PAC_URI = ""; # Your PAC file URI goes here | |
my $url = @ARGV ? $ARGV[-1] : ''; | |
my $proxy = ''; | |
$url =~ s/^\s+|\s+$//g; | |
if ($url =~ /$RE{URI}/) { | |
my $pac = HTTP::ProxyPAC->new(URI->new($PAC_URI)); | |
my $res = $pac->find_proxy($url); | |
$proxy = $res->proxy ? $res->proxy : '""'; | |
unshift @ARGV, "--proxy $proxy"; | |
} else { | |
push @ARGV, ""; | |
} | |
my $options = join ' ', @ARGV[0 .. ($#ARGV - 1)]; | |
system("/usr/bin/curl $options --proxy $proxy $url"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment