File: check_server

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 (61 lines) | stat: -rwxr-xr-x 1,482 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/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. The url is fetched twice to see if the server supports caching
or not.

The first line of output will say that the url is fetched from the
server (unless you have fetched this url before and it is already in
the cache).

The second line of output will tell you what happened when we tried
to fetch the same url a second time:

Fetching ... from server: 
The server returned a new page that was different
from the page that was fetched the previous time.
Caching didn't improve anything.


Fetching ... unchanged from server: 
The server indicated that caching was not possible, 
but still returned the exact same page as the last 
time. Caching didn't improve anything.


Fetching ... from cache: 
The server returned a short note saying that the
contents of the cache was still up-to-date. If the
page was big, the cache saved us a lot of bandwidth.

The cache is stored in the directory /tmp/cache. This directory must
exist and be empty before the command is run.

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.
} );

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

# and twice.
$data = get( $url );