Subject: | Add option for API timeout |
Hi
Net::Akismet currently doesn't set any specific timeout for API requests. This means that the default LWP::UserAgent timeout is used. This is currently 3 minutes.
If $akismet->check() is used in a FCGI or a similar handler, other things will timeout sooner than 3 minutes. This is usually not what you want.
The attached patch adds an optional TIMEOUT argument to new() that is propagated to the underlying LWP::UserAgent object. It allows the API timeout to be specified as necessary for each specific application.
Best regards
Tomaž
Subject: | add-timeout.patch |
Index: libnet-akismet-perl-0.05/lib/Net/Akismet.pm
===================================================================
--- libnet-akismet-perl-0.05.orig/lib/Net/Akismet.pm 2016-08-14 12:03:00.192496688 +0200
+++ libnet-akismet-perl-0.05/lib/Net/Akismet.pm 2016-08-14 12:23:05.934800899 +0200
@@ -75,6 +75,10 @@
If supplied, the API version. The default is 1.1
+=item TIMEOUT
+
+If supplied, sets a timeout (in seconds) for the API. The default is LWP::UserAgent default (3 minutes currently).
+
=back
If verification of the key was unsuccessful C<new()> returns C<undef>.
@@ -99,6 +103,8 @@
$agent = "$params{USER_AGENT} $agent" if $params{USER_AGENT};
$self->{ua}->agent($agent);
+ $self->{ua}->timeout($self->{TIMEOUT}) if $params{TIMEOUT};
+
$self->{SERVICE_HOST} = $params{SERVICE_HOST} || 'rest.akismet.com';
$self->{SERVICE_VERSION} = $params{SERVICE_VERSION} || '1.1';