]> Sergey Matveev's repositories - public-inbox.git/commitdiff
lei_curl: use http.proxy knob via URL match for curl
authorEric Wong <e@80x24.org>
Wed, 3 Nov 2021 20:35:55 +0000 (20:35 +0000)
committerEric Wong <e@80x24.org>
Thu, 4 Nov 2021 03:29:38 +0000 (03:29 +0000)
Using the --proxy on the command-line affects the entire
lei invocation, and users searching HTTP(S) remotes and
writing to an IMAP folder may want more fine-grained proxy
use:

  lei q -o imap://no-proxy.example/foo -O https://need-proxy.example/bar ...

lib/PublicInbox/LeiCurl.pm

index ce57e7963ae98743440e58f64640f10661ff9cb4..5ffade9976cb43a194e784c955d4b515d2b8a90f 100644 (file)
@@ -75,6 +75,11 @@ EOM
 sub for_uri {
        my ($self, $lei, $uri, @opt) = @_;
        my $pfx = torsocks($self, $lei, $uri) or return; # error
 sub for_uri {
        my ($self, $lei, $uri, @opt) = @_;
        my $pfx = torsocks($self, $lei, $uri) or return; # error
+       if ($uri->scheme =~ /\Ahttps?\z/i) {
+               my $cfg = $lei->_lei_cfg;
+               my $p = $cfg ? $cfg->urlmatch('http.Proxy', $$uri) : undef;
+               push(@opt, "--proxy=$p") if defined($p);
+       }
        bless [ @$pfx, @$self, @opt, $uri->as_string ], ref($self);
 }
 
        bless [ @$pfx, @$self, @opt, $uri->as_string ], ref($self);
 }