Debian Codegraph @

examples/check_server

raw
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
14 mode. The url is fetched twice to see if the server supports caching
15 or not.
16
17 The first line of output will say that the url is fetched from the
18 server (unless you have fetched this url before and it is already in
19 the cache).
20
21 The second line of output will tell you what happened when we tried
22 to fetch the same url a second time:
23
24 Fetching ... from server:
25 The server returned a new page that was different
26 from the page that was fetched the previous time.
27 Caching didn't improve anything.
28
29
30 Fetching ... unchanged from server:
31 The server indicated that caching was not possible,
32 but still returned the exact same page as the last
33 time. Caching didn't improve anything.
34
35
36 Fetching ... from cache:
37 The server returned a short note saying that the
38 contents of the cache was still up-to-date. If the
39 page was big, the cache saved us a lot of bandwidth.
40
41 The cache is stored in the directory /tmp/cache. This directory must
42 exist and be empty before the command is run.
43
44 EOD
45
46 exit;
47 }
48
49 my( $url ) = @ARGV;
50
51 HTTP::Cache::Transparent::init( {
52 BasePath => "/tmp/cache", # Directory to store the cache in.
53 Verbose => 1, # Print messages to STDERR. Default is 0.
54 } );
55
56 # Fetch once
57 my $data = get( $url );
58
59 # and twice.
60 $data = get( $url );
61