summaryrefslogtreecommitdiffstats
path: root/debian/htdig/htdig-3.2.0b6/contrib/handler.pl
blob: 53ec7f34cea22bb798cb4a78b37d95d37eaad6ec (plain)
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
#!/usr/bin/perl
# 
# handler.pl
# Sample ExternalTransport handler for HTTP and HTTPS using curl
# for the ht://Dig package 3.2.x and higher
# by Geoffrey Hutchison <ghutchis@wso.williams.edu>
# Copyright (c) 1999 under the terms of the GNU Public License vesion 2 (GPL)
#
# handler.pl protocol url config_file
#
# Really a simplistic example--this should probably use Perl's LWP for HTTP/HTTPS/FTP
# Right now it uses the program 'curl' to do HTTP or HTTPS transactions.
#

my $curl_path="/usr/local/bin/curl";
my $protocol=$ARGV[0];
my $url=$ARGV[1];
my $config_file=$ARGV[2];

open (DOC, "$curl_path -i $url |") || die "s:\t404\nr:\tCan't open curl!\n";
while ( my $line = <DOC> ) {
    if ( $line =~ /^HTTP.?\/\d.\d\s(\d\d\d)\s(.*)/io ) {
	print "s:\t$1\n";
	print "r:\t$2\n";
    } elsif ( $line =~ /^last-modified: (.*)$/io ) {
	print "m:\t$1\n";
    } elsif ( $line =~ /^content-type: (.*)$/io ) {
	print "t:\t$1\n";
    } elsif ( $line =~ /^content-length: (.*)$/io ) {
	print "l:\t$1\n";
    } elsif ( $line =~ /^location: (.*)$/io ) {
	print "u:\t$1\n";
    }

    last if ( $line =~ /^\s*$/ )
}

local($/) = undef;
my $text = <DOC>;
close(DOC);

print "\n$text";