Hi Gisle,

On Wed, Sep 29, 2004 at 10:47:23AM -0700, Gisle Aas wrote:
> Bill Moseley <[EMAIL PROTECTED]> writes:
> 
> > I'm using keep alives and the form of $ua->get() that uses a callback
> > function to read the data as it arrives.
> > 
> > If the callback function dies will the connection always be broken?
> 
> Yes, unless it dies after the last part of the response has actually
> been read.

I'm not seeing that.  If I fetch a small document and in my callback I
print out the content passed in I see all the content.  Then if I die
the next request is a new connection.

LWP::UserAgent 2.32



#!perl
use warnings;
use strict;
use LWP::UserAgent;

my $ua = LWP::UserAgent->new( keep_alive => 1 );

my $request = HTTP::Request->new('GET', 'http://localhost/apache/1.html');

my $callback = sub {
    my ( $content, $response ) = @_;
    print "Content-Length: ",
            $response->content_length,
            ".  Passed content size: ",
            length($content),
            ".\n";
    die "dead\n";
};

my $response = $ua->simple_request( $request, $callback, 4096 );

print "Connection header from second request: ",
      $ua->simple_request( $request )->header('Connection'),
      "\n";

$ perl lwp.pl
Content-Length: 181.  Passed content size: 181.
Connection header from second request: Keep-Alive

Remove the "die" and the second connection is on the same connection
(and no Keep-Alive header).

Thanks,


-- 
Bill Moseley
[EMAIL PROTECTED]

Reply via email to