Skip to content

Instantly share code, notes, and snippets.

Last active June 15, 2022 04:59
  • Star 9 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save mpcabd/b09688a0f5ec183afc68 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
# To read more about this script go to:
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