Perl Home Search CGI

3.2 HTTP Header


14.02.2006

3.1 Post to Newsgroup [  up  ] - [ top ] 3.3 check for the existance of an URI (LWP)

use LWP::Simple;

# Header ermitteln
my ($content_type, $document_length, $modified_time, $expires, $server) = head $ARGV[0];

$content_type    ||= 'text/html';
$modified_time   ||= int(time()) - 720 * 3600; # 30 days ago if not set ;-)
$expires         ||= int(time()) + 720 * 3600; # 30 days     if not set ;-)
$document_length ||= -1;

my $mtime_disp = scalar localtime($modified_time);
my $etime_disp = scalar localtime($expires);

print qq~
        content_type    $content_type
        document_length $document_length
        modified_time   $mtime_disp
        expires         $etime_disp
        server          $server

~;

my $content = get $ARGV[0];

print $content;

Test of code above

[retoh@dhcppc1 retoh]$ ./lwphead.pl http://www.w3c.org|more

        content_type    text/html; charset=us-ascii
        document_length 21340
        modified_time   Thu Jun 27 21:55:22 2002
        expires         Sun Jun 30 10:14:47 2002
        server          Apache/1.3.26 (Unix) PHP/3.0.18


<?xml version="1.0" encoding="us-ascii"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US"
lang="en-US">

...

copyright by reto - created with mytexi