| 1 | package App::MadEye::Plugin::Agent::HTTP; | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | use Furl; | ||
| 5 | use App::MadEye::Plugin::Agent::Base; | ||
| 6 | |||
| 7 | our $TIMEOUT = 15; | ||
| 8 | |||
| 9 | sub is_dead { | ||
| 10 | my ($self, $url) = @_; | ||
| 11 | |||
| 12 | my $ua = Furl->new( | ||
| 13 | timeout => $TIMEOUT, | ||
| 14 | agent => $self->config->{config}->{user_agent} || "App::MadEye($App::MadEye::VERSION)", | ||
| 15 | ); | ||
| 16 | my $res = $ua->get($url); | ||
| 17 | |||
| 18 | if ($res->code == 200) { | ||
| 19 | if (my $part = $self->config->{config}->{part}) { | ||
| 20 | if (index($res->content, $part) >= 0) { | ||
| 21 | return; # ok | ||
| 22 | } else { | ||
| 23 | return "contents does not contain $part"; | ||
| 24 | } | ||
| 25 | } else { | ||
| 26 | return 0; | ||
| 27 | } | ||
| 28 | } else { | ||
| 29 | return join( "\n", $res->code, $res->message, $res->content ); | ||
| 30 | } | ||
| 31 | } | ||
| 32 | |||
| 33 | 1; | ||
| 34 | __END__ |