App-Raider
view release on metacpan or search on metacpan
lib/App/Raider/WebTools.pm view on Meta::CPAN
my $url = $in->{url};
my $req = GET($url);
$req->header('User-Agent' => 'raider/0.001');
my $f = $http->do_request(request => $req);
my $resp = eval { $f->get };
return $tool->text_result("Error: $@", 1) if $@;
unless ($resp->is_success) {
return $tool->text_result(
sprintf("HTTP %s for %s", $resp->status_line, $url), 1);
}
my $body = $resp->decoded_content // '';
if (length($body) > $max_fetch_bytes) {
$body = substr($body, 0, $max_fetch_bytes) . "\n[truncated]\n";
}
my $ctype = $resp->header('Content-Type') // '';
if (!$in->{as_html} && $ctype =~ m{text/html}i) {
$body = _flatten_html($body);
}
my $header = sprintf("URL: %s\nStatus: %s\nContent-Type: %s\n\n",
$url, $resp->status_line, $ctype);
return $tool->text_result($header . $body);
( run in 0.743 second using v1.01-cache-2.11-cpan-9581c071862 )