libwww-perl-5.53_90 Keep Alives

Bill Moseley (moseley@hank.org)
Thu, 19 Apr 2001 10:51:45 -0700


Great stuff, Gisle!  Thanks.

Just starting to look, but a few questions:

1) Is there a way to turn keep alive off once enabled?

I'm using this code to enable:

if ( $this_server->keep_alive ) {

    eval 'require LWP::Protocol::http11;';
    if ( $@ ) {
        warn "Cannot use keep alives -- $@\n";
    } else {
        LWP::Protocol::implementor('http', 'LWP::Protocol::http11');
    }
}

But I'd like a way to turn it back off again when $my_server->keep_alive
becomes false (e.g. when I start fetching from another server).

I tried simply:
       LWP::Protocol::implementor('http', 'LWP::Protocol::http');

But then my request fails.


2) With keep alives on the request following a non-200 response returns a
500, although the server logs a 200 for the request.  Example code is
attached below.


3) Also, I see these warning -- sorry, I haven't looked into them yet.

Use of uninitialized value in length at
/usr/local/lib/perl5/site_perl/5.6.0/LWP/Protocol.pm line 242.
Use of uninitialized value in split at
/usr/local/lib/perl5/site_perl/5.6.0/LWP/Protocol/http11.pm line 292


-- 
Example code:

#!/usr/local/bin/perl -w
use strict;
    require LWP::UserAgent;
    require LWP::Protocol::http11;
    LWP::Protocol::implementor('http', 'LWP::Protocol::http11');

    my $ua = LWP::UserAgent->new;

    my @urls = qw(
        http://www.infopeople.org/blabla.html
        http://www.infopeople.org/index.html
    );

    for ( @urls ) {
        my $request = HTTP::Request->new('GET', $_ );
        my $response = $ua->simple_request($request);
        print join( ' ',
                ( $response->is_success ? '+Fetched' : '-Failed' ),
                $response->request->uri->canonical,
                $response->code,
                $response->content_type,
                $response->content_length,
           ),"\n";
    }

> perl test.pl
"my" variable @h masks earlier declaration in same scope at
/usr/local/lib/perl5/site_perl/5.6.0/LWP/Protocol/http11.pm line 254.
-Failed http://www.infopeople.org/src/guide.html 301 text/html
charset=iso-8859-1
-Failed http://www.infopeople.org/newstuff.html 500

With a 404 I get a warning:
-Failed http://www.infopeople.org/blabla.html 404 text/html
Illegal hexadecimal digit '     ' ignored at
/usr/local/lib/perl5/site_perl/5.6.0/Net/HTTP.pm line 305.

Comment out the following line and it works fine:
   LWP::Protocol::implementor('http', 'LWP::Protocol::http11');

> perl test.pl
"my" variable @h masks earlier declaration in same scope at
/usr/local/lib/perl5/site_perl/5.6.0/LWP/Protocol/http11.pm line 254.
-Failed http://www.infopeople.org/src/guide.html 301 text/html
charset=iso-8859-1
+Fetched http://www.infopeople.org/newstuff.html 200 text/html 8337


Bill Moseley
mailto:moseley@hank.org