logo

ap-client

CLI-based client / toolbox for ActivityPub Client-to-Servergit clone https://hacktivis.me/git/ap-client.git
commit: fac7d5370ab59b025824d4c02861b7569442b4c1
parent 62f61e651e316701a17f0c1565d2cb666a4638d9
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Sun,  7 Nov 2021 17:19:02 +0100

Add support for HTTP Basic Auth

Diffstat:

Map-fetch.pl16++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/ap-fetch.pl b/ap-fetch.pl @@ -9,24 +9,32 @@ no warnings; # Wide Character… use Getopt::Std; use LWP::UserAgent; +use HTTP::Request::Common; my %options=(); my $ua = LWP::UserAgent->new; -getopts("rj", \%options); +getopts("rju:", \%options); if($#ARGV != 0) { - print "usage: ap-fetch.pl [-r|-j] <url>\n"; - print " -r Raw output\n"; + print "usage: ap-fetch.pl [-r|-j|-u user:pass] <url>\n"; print " -j Pipe into jq(1)\n"; - print "Otherwise it pipes into ap-represent.pl.\n"; + print " -r Raw output\n"; + print " -u user:pass HTTP Basic Auth credentials\n"; + print "By default, when -j and -r are absent it pipes the data into ap-represent.pl.\n"; exit 1; } + $ua->agent("AP-Client fetch <https://hacktivis.me/git/ap-client/>"); my $req = HTTP::Request->new(GET => $ARGV[0]); $req->header('Accept' => 'application/activity+json'); +if(defined $options{u}) { + my ($user, $password) = split(/:/, $options{u}); + $req->authorization_basic($user, $password); +} + my $res = $ua->request($req); if($res->is_success) {