Bill Moseley <[EMAIL PROTECTED]> writes:
> At 09:34 AM 04/23/01 -0700, Gisle Aas wrote:
> > Keep-alive and the new HTTP/1.1 module can now be simply
> > enabled with something like:
> >
> > LWP::UserAgent->new(keep_alive => 1);
>
> Humm, my mind isn't working. Do (can) you have a kepp_alive method to
> set/get that value.
There is no keep_alive method. It is just a constructor option for now.
> The problem is I'm using LWP::RobotUA, and I think its new() doesn't pass
> the parameters to LWP::UserAgent when creating the ua object.
>
> In other words, how do I turn on keep_alives with RobotUA?
RobotUA should be fixed to take options in a similar way and pass them
to its superclass.
> And now (_91) LWP::UserAgent does the require on http11 so I don't need to
> load it in my code as in then _90 version, correct?
This is correct.
> In my code I was wrapping the require http11 in an eval block so I could
> fallback to non-keep alives if the require on http11 failed (I assumed not
> everyone that will be using my code will have a current LWP with
> keep_alives enabled).
Seems like a good idea.
> I assume old versions of LWP (without keep_alive support) will just ignore
> that passed-in parameter.
Correct.
> My old code using the eval { require http11 }
> would warn to upgrade their copy of LWP.
Which might be a reason to continue to keep it that way. The
interface to this stuff is anyway still experimental. It will not be
set in stone until I make a 5.54 release.
You might also simply just test $LWP::VERSION and suggest upgrading at
some suitable threshold.
> Can I continue to use the _90 method, or is there a better way?
>
> if ( $server->{keep_alive} ) {
>
> eval 'require LWP::Protocol::http11;';
> if ( $@ ) {
> warn "Cannot use keep alives, please upgrade LWP -- $@\n";
> } else {
> LWP::Protocol::implementor('http', 'LWP::Protocol::http11');
> }
> } else {
> require LWP::Protocol::http;
> LWP::Protocol::implementor('http', 'LWP::Protocol::http');
This else-branch should not be needed as this is the default.
> }
I would simply write it like this:
if ( $server->{keep_alive} ) {
eval {
require LWP::Protocol::http11;
LWP::Protocol::implementor('http', 'LWP::Protocol::http11');
};
warn "Cannot use keep alives, please upgrade LWP -- $@\n" if $@;
}
But eventually LWP::Protocol::http11 will become the default and be
renamed LWP::Protocol::http. At that point this code should suggest
downgrading :-)
> And for picking which module, I do this:
>
> if ( $server->{ignore_robots_file} ) {
> $ua = LWP::UserAgent->new();
> return unless $ua;
> $ua->agent( $server->{agent} );
> $ua->from( $server->{email} );
>
> } else {
> $ua = LWP::RobotUA->new( $server->{agent}, $server->{email} );
> return unless $ua;
> $ua->delay( $server->{delay_min} || 0.1 );
> }
Seems ok for now. After we have fixed RobotUA I would think this
should work:
my $uaclass = $server->{ignore_robots_file} ? "LWP::UserAgent" :
"LWP::RobotUA";
$ua = $uaclass->new(agent => $server->{agent},
from => $server->{email},
keep_alive => $server->{keep_alive},
);
return unless $ua;
eval { $ua->delay( $server->{delay_min} || 0.1 ); };
Regards,
Gisle