W3C home > Mailing lists > Public > www-validator@w3.org > August 1998

LWP Code

From: Randy Winch <gumby@cafes.net>
Date: Wed, 26 Aug 1998 03:40:47 -0500
Message-ID: <35E3CA0F.87F35C82@cafes.net>
To: www-validator@w3.org
Hi All,

Here is a first pass at coding for using LWP directly...

--------------------------
Old code:
--------------------------
open( URI, "$grabber \"$uri_escaped\" |" ) || die "couldn't retrieve
uri: $!";
@file = <URI>;
close( URI ) || die "couldn't close uri retrieval pipe: $!";

# skip the request headers
while ( $_ = shift( @file ) ) {
    chop;
    last if /^$/;
}

# check the response headers
while ( $_ = shift( @file ) ) {
    chop;
    if (/^HTTP\/[0-9\.]+ [0-9][0-9][0-9] .*/ ) {
        ( ( $httpversion, $response, $message ) =
            ( /^(HTTP\/[0-9\.]+) ([0-9][0-9][0-9]) (.*)/ ) );
    }
    if (/^Location: / ) {
        ( ( $redirect_uri ) = ( /^Location: (.*)/ ) );
        $redirect_uri =~ s/\s*$//g;     # it has a trailing space
sometimes (?)
    }
    last if /^$/;
}
--------------------------
New Code:
--------------------------
require LWP::UserAgent;

$ua=new LWP::UserAgent;
$request=new HTTP::Request('GET',$uri_escaped);

$my_response=$ua->request($request);
($response,$message)=($my_response->status_line=~/([0-9][0-9][0-9])
(.*)/);
@file=split(/^/,$my_response->content);
--------------------------
Hope this helps. Also, is a gz of the sgml-lib directory available ?

Randy Winch
Received on Wednesday, 26 August 1998 04:39:29 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Wednesday, 25 April 2012 12:13:51 GMT