File: check_server_approve

package info (click to toggle)
libhttp-cache-transparent-perl 1.4-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 140 kB
  • sloc: perl: 342; makefile: 4
file content (35 lines) | stat: -rwxr-xr-x 659 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/perl -w 

use strict;

use LWP::Simple;
use HTTP::Cache::Transparent;

if( scalar( @ARGV ) != 1 )
{
  print << "EOD";
usage: check_server <url>

Fetches a url via the HTTP::Cache::Transparent module in verbose mode. 
Uses an ApproveContent sub that only approves responses with a
successful response-code.

EOD

  exit;
}

my( $url ) = @ARGV;

HTTP::Cache::Transparent::init( { 
  BasePath  => "/tmp/cache", # Directory to store the cache in. 
  Verbose   => 1,            # Print messages to STDERR. Default is 0.
  NoUpdate  => 0,
  ApproveContent => sub { return $_[0]->is_success(); },
} );

# Fetch once
my $data = get( $url );

print $data;