Skip to content

Instantly share code, notes, and snippets.

@zhanglianbo35
Forked from mpcabd/curlp.pl
Created March 13, 2018 15:44
Show Gist options
  • Save zhanglianbo35/f9f890a1c65fcacebceb03a2e1c2ab5e to your computer and use it in GitHub Desktop.
Save zhanglianbo35/f9f890a1c65fcacebceb03a2e1c2ab5e to your computer and use it in GitHub Desktop.
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