From d283e4ca1aeb6ca8cc0951c8495f778071076013 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sun, 10 Feb 2019 17:22:06 +0000 Subject: useragent: Automatically choose whether to use LWPx::ParanoidAgent The simple implementation of this, which I'd prefer to use, would be: if we can import LWPx::ParanoidAgent, use it; otherwise, use LWP::UserAgent. However, aggregate has historically worked with proxies, and LWPx::ParanoidAgent quite reasonably refuses to work with proxies (because it can't know whether those proxies are going to do the same filtering that LWPx::ParanoidAgent would). Signed-off-by: Simon McVittie --- IkiWiki/Plugin/aggregate.pm | 5 ++++- IkiWiki/Plugin/blogspam.pm | 16 ++++------------ IkiWiki/Plugin/openid.pm | 12 ++++-------- IkiWiki/Plugin/pinger.pm | 21 ++++++++++----------- 4 files changed, 22 insertions(+), 32 deletions(-) (limited to 'IkiWiki') diff --git a/IkiWiki/Plugin/aggregate.pm b/IkiWiki/Plugin/aggregate.pm index 05e22a290..8f0870e2e 100644 --- a/IkiWiki/Plugin/aggregate.pm +++ b/IkiWiki/Plugin/aggregate.pm @@ -513,7 +513,10 @@ sub aggregate (@) { } $feed->{feedurl}=pop @urls; } - my $ua=useragent(); + # Using the for_url parameter makes sure we crash if used + # with an older IkiWiki.pm that didn't automatically try + # to use LWPx::ParanoidAgent. + my $ua=useragent(for_url => $feed->{feedurl}); my $res=URI::Fetch->fetch($feed->{feedurl}, UserAgent=>$ua); if (! $res) { $feed->{message}=URI::Fetch->errstr; diff --git a/IkiWiki/Plugin/blogspam.pm b/IkiWiki/Plugin/blogspam.pm index 3eb4cf8b3..3835f52ca 100644 --- a/IkiWiki/Plugin/blogspam.pm +++ b/IkiWiki/Plugin/blogspam.pm @@ -57,18 +57,10 @@ sub checkconfig () { }; error $@ if $@; - eval q{use LWPx::ParanoidAgent}; - if (!$@) { - $client=LWPx::ParanoidAgent->new(agent => $config{useragent}); - } - else { - eval q{use LWP}; - if ($@) { - error $@; - return; - } - $client=useragent(); - } + # Using the for_url parameter makes sure we crash if used + # with an older IkiWiki.pm that didn't automatically try + # to use LWPx::ParanoidAgent. + $client=useragent(for_url => $config{blogspam_server}); } sub checkcontent (@) { diff --git a/IkiWiki/Plugin/openid.pm b/IkiWiki/Plugin/openid.pm index 35ef52a58..eb21955e9 100644 --- a/IkiWiki/Plugin/openid.pm +++ b/IkiWiki/Plugin/openid.pm @@ -219,14 +219,10 @@ sub getobj ($$) { eval q{use Net::OpenID::Consumer}; error($@) if $@; - my $ua; - eval q{use LWPx::ParanoidAgent}; - if (! $@) { - $ua=LWPx::ParanoidAgent->new(agent => $config{useragent}); - } - else { - $ua=useragent(); - } + # We pass the for_url parameter, even though it's undef, because + # that will make sure we crash if used with an older IkiWiki.pm + # that didn't automatically try to use LWPx::ParanoidAgent. + my $ua=useragent(for_url => undef); # Store the secret in the session. my $secret=$session->param("openid_secret"); diff --git a/IkiWiki/Plugin/pinger.pm b/IkiWiki/Plugin/pinger.pm index b2d54af8a..ec764caee 100644 --- a/IkiWiki/Plugin/pinger.pm +++ b/IkiWiki/Plugin/pinger.pm @@ -70,17 +70,16 @@ sub ping { eval q{use Net::INET6Glue::INET_is_INET6}; # may not be available my $ua; - eval q{use LWPx::ParanoidAgent}; - if (!$@) { - $ua=LWPx::ParanoidAgent->new(agent => $config{useragent}); - } - else { - eval q{use LWP}; - if ($@) { - debug(gettext("LWP not found, not pinging")); - return; - } - $ua=useragent(); + eval { + # We pass the for_url parameter, even though it's + # undef, because that will make sure we crash if used + # with an older IkiWiki.pm that didn't automatically + # try to use LWPx::ParanoidAgent. + $ua=useragent(for_url => undef); + }; + if ($@) { + debug(gettext("LWP not found, not pinging").": $@"); + return; } $ua->timeout($config{pinger_timeout} || 15); -- cgit v1.2.3