| 1 |
#!/usr/bin/perl -w |
| 2 |
|
| 3 |
use strict; |
| 4 |
|
| 5 |
use LWP::Simple; |
| 6 |
use HTTP::Cache::Transparent; |
| 7 |
|
| 8 |
if( scalar( @ARGV ) != 1 ) |
| 9 |
{ |
| 10 |
print << "EOD"; |
| 11 |
usage: check_server <url> |
| 12 |
|
| 13 |
Fetches a url via the HTTP::Cache::Transparent module in verbose mode. |
| 14 |
Uses an ApproveContent sub that only approves responses with a |
| 15 |
successful response-code. |
| 16 |
|
| 17 |
EOD |
| 18 |
|
| 19 |
exit; |
| 20 |
} |
| 21 |
|
| 22 |
my( $url ) = @ARGV; |
| 23 |
|
| 24 |
HTTP::Cache::Transparent::init( { |
| 25 |
BasePath => "/tmp/cache", # Directory to store the cache in. |
| 26 |
Verbose => 1, # Print messages to STDERR. Default is 0. |
| 27 |
NoUpdate => 0, |
| 28 |
ApproveContent => sub { return $_[0]->is_success(); }, |
| 29 |
} ); |
| 30 |
|
| 31 |
# Fetch once |
| 32 |
my $data = get( $url ); |
| 33 |
|
| 34 |
print $data; |
| 35 |
|