Last active
April 9, 2024 22:11
-
-
Save mpcabd/b09688a0f5ec183afc68 to your computer and use it in GitHub Desktop.
curl with Proxy auto-config (PAC) files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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