Bug#737121: ikiwiki: [PATCH] Implement configuration option to set the user agent string for outbound HTTP requests

2014-01-31 Thread Tuomas Jormola
Hi,

On Thu, Jan 30, 2014 at 02:47:41PM -0400, Joey Hess wrote:
 This looks good, but have you checked that all of the places
 $config{useragent} is passed to do the right thing when it is undef?
Yes I have.

Case 1: IkiWiki::useragent() using LWP::UserAgent-new().
$agent variable defined from the option hash passed to LWP::UserAgent-new():
https://metacpan.org/source/GAAS/libwww-perl-6.05/lib/LWP/UserAgent.pm#L28
Value of $agent variable checked with defined(), if undef using
the default implementation as if no agent key passed to
LWP::UserAgent-new() at all:
https://metacpan.org/source/GAAS/libwww-perl-6.05/lib/LWP/UserAgent.pm#L112

Case 2: Where LWPx::ParanoidAgent-new() is being used.
LWPx::ParanoidAgent is a sub-class of LWP::UserAgent, so option hash
passed to LWPx::ParanoidAgent-new() is used as with LWP::UserAgent-new():
https://metacpan.org/source/SAXJAZMAN/LWPx-ParanoidAgent-1.10/lib/LWPx/ParanoidAgent.pm#L22
https://metacpan.org/source/SAXJAZMAN/LWPx-ParanoidAgent-1.10/lib/LWPx/ParanoidAgent.pm#L30

On a related note, should the cookie jar option be passed when using
LWPx::ParanoidAgent-new()?

So I think it's ok.

br,
Tuomas

 
 -- 
 see shy jo




signature.asc
Description: Digital signature


Bug#737121: ikiwiki: [PATCH] Implement configuration option to set the user agent string for outbound HTTP requests

2014-01-30 Thread Tuomas Jormola
Package: ikiwiki
Version: 3.20140125
Severity: wishlist

By default, LWP::UserAgent used by IkiWiki to perform outbound HTTP
requests sends the string libwww-perl/version number as User-Agent
header in HTTP requests. Some blogging platforms have blacklisted the
user agent and won't serve any content for clients using this user agent
string. With IkiWiki configuration option useragent it's now possible
to define a custom string that is used for the value of the User-Agent
header.
---
 IkiWiki.pm   |9 +
 IkiWiki/Plugin/openid.pm |2 +-
 IkiWiki/Plugin/pinger.pm |2 +-
 3 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/IkiWiki.pm b/IkiWiki.pm
index b7080bb..eb48096 100644
--- a/IkiWiki.pm
+++ b/IkiWiki.pm
@@ -527,6 +527,14 @@ sub getsetup () {
safe = 0, # hooks into perl module internals
rebuild = 0,
},
+   useragent = {
+   type = string,
+   default = undef,
+   example = Wget/1.13.4 (linux-gnu),
+   description = set custom user agent string for outbound HTTP 
requests e.g. when fetching aggregated RSS feeds,
+   safe = 0,
+   rebuild = 0,
+   },
 }
 
 sub defaultconfig () {
@@ -2301,6 +2309,7 @@ sub useragent () {
return LWP::UserAgent-new(
cookie_jar = $config{cookiejar},
env_proxy = 1, # respect proxy env vars
+   agent = $config{useragent},
);
 }
 
diff --git a/IkiWiki/Plugin/openid.pm b/IkiWiki/Plugin/openid.pm
index d369e30..3b96e4b 100644
--- a/IkiWiki/Plugin/openid.pm
+++ b/IkiWiki/Plugin/openid.pm
@@ -238,7 +238,7 @@ sub getobj ($$) {
my $ua;
eval q{use LWPx::ParanoidAgent};
if (! $@) {
-   $ua=LWPx::ParanoidAgent-new;
+   $ua=LWPx::ParanoidAgent-new(agent = $config{useragent});
}
else {
$ua=useragent();
diff --git a/IkiWiki/Plugin/pinger.pm b/IkiWiki/Plugin/pinger.pm
index fb0f3ba..b2d54af 100644
--- a/IkiWiki/Plugin/pinger.pm
+++ b/IkiWiki/Plugin/pinger.pm
@@ -72,7 +72,7 @@ sub ping {
my $ua;
eval q{use LWPx::ParanoidAgent};
if (!$@) {
-   $ua=LWPx::ParanoidAgent-new;
+   $ua=LWPx::ParanoidAgent-new(agent = 
$config{useragent});
}
else {
eval q{use LWP};
-- 
1.7.9.5


-- 
To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org



Bug#737121: ikiwiki: [PATCH] Implement configuration option to set the user agent string for outbound HTTP requests

2014-01-30 Thread Joey Hess
This looks good, but have you checked that all of the places
$config{useragent} is passed to do the right thing when it is undef?

-- 
see shy jo


signature.asc
Description: Digital signature