Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^3: url issues using HTTP::Tiny

by Anonymous Monk
on Sep 18, 2019 at 19:15 UTC ( [id://11106347]=note: print w/replies, xml ) Need Help??


in reply to Re^2: url issues using HTTP::Tiny
in thread url issues using HTTP::Tiny

Don't worry! HTTP::Tiny will rot bits as webmasters implement HTTPS Everywhere! except for the backlash of hip retro unencrypted sites! Then one day HTTP::Tiny, after years of recommendations followed by years of disillusionment [YOU ARE HERE] followed by years of disparagement, will be unceremoniously deprecated and REMOVED FROM THE PERL CORE!

If it could happen to CGI, it will probably happen to HTTP::Tiny 🔋🗑

UNLESS someone rescues HTTP::Tiny to evolve some sort of fallback functionality along the lines of HTTP::Any like this silly core one-liner, when fed an https url on an https-less perl, will fail and fallback on a random selection of wget or curl (or, like, all known https clients on every operating system?):

perl -MIPC::Cmd=can_run,run -MHTTP::Tiny -le'@c=({wget=>"wget -O-"},{c +url=>"curl"});$u=shift;$r=HTTP::Tiny->new->get($u);if($r->{status}==5 +99){($a,$b)=%{$c[rand@c]};if(my $cmd=can_run($a)){if(scalar run(comma +nd=>"$b $u",buffer=>\my $data)){print"$data\n$cmd"}}}else{print"$r->{ +content}\ntiny"}' "https://www.perlmonks.org"
perl -MIPC::Cmd=can_run,run -MHTTP::Tiny -le' @c=({wget=>"wget -O-"},{curl=>"curl"}); $u=shift; $r=HTTP::Tiny->new->get($u); if($r->{status}==599){ ($a,$b)=%{$c[rand@c]}; if(my $cmd=can_run($a)){ if(scalar run(command=>"$b $u",buffer=>\my $data){ print"$data\n$cmd" } } } else{print"$r->{content}\ntiny"}' "https://www.perlmonks.org"
Let's fix it!

Replies are listed 'Best First'.
Re^4: url issues using HTTP::Tiny
by Corion (Patriarch) on Sep 19, 2019 at 07:35 UTC

    The reason that HTTP::Tiny is in core is as a fallback for CPAN to use when wget or curl don't work. So there is no need to "fix" this.

      Caveat: so long as CPAN never needs to access an https URL.

      The core module File::Fetch solves the problem by trying LWP, HTTP::Tiny, wget, curl, lftp, fetch, HTTP::Lite, lynx & iosock:
      perl -MHTTP::Tiny -le'print HTTP::Tiny->new->get("https://perlmonks.or +g/")->{content}'
      IO::Socket::SSL 1.42 must be installed for https support
      Net::SSLeay 1.49 must be installed for https support
      
      perl -MFile::Fetch -le'$f=File::Fetch->new(uri=>"https://perlmonks.org +/")->fetch(to=>\my$data)or die$f->error;print$data'
      Success!
      

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11106347]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (4)
As of 2024-03-29 00:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found