develooper Front page | perl.libwww | Postings from July 2001

Re: LWP/Solaris missing EOF bug

Thread Next
Bob Fillmore
July 9, 2001 08:39
Re: LWP/Solaris missing EOF bug
Message ID:
I have just spent a few hours wrestling with this bug, and came up with
a workaround.
After looking at the LWP source code I realized that it doesn't look at
Content-Length header returned by the server, so I added a request
callback routine
to read the number of bytes specified in the Content-Length header:

sub read_chunk {
        my($chunk, $res, $prot) = @_;
        $res->{_content} .= $chunk;
        if ($totlength == 0) {
                $hlength = scalar $res->header("Content-Length");
                print "Content-Length: $hlength\n";
        $totlength += length($chunk);
        print "Length: " . length($chunk) . "  $totlength  $hlength\n";
        die "All data read" if (($hlength>0) && ($totlength>=$hlength));


$link = "";
$request = new HTTP::Request('GET',$link,$http_headers);
$hlength = 0;
$totlength = 0;
$response = $agent->request($request,\&read_chunk);

This code seems to work reliably during testing, but I haven't tried it
on a
large number of URLs yet.   Also, I still seem to have a problem with
requests, which don't seem to call the callback routine.

Why doesn't LWP do this already?  (use the Content-Length header if

     - Bob Fillmore

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About