Subject: | LWP UserAgent Credentials |
Hello-
I was working with LWP::UserAgent yesterday, when I discovered that using the credentials method with basic authentication required me to know the exact realm. I modified my copy of LWP/UserAgent.pm so that will accept a default realm, and it works great. I'm submitting this because I think it would be a great addition to the module.
My code (just 2 extra lines) first performs the traditional hash check for a realm match, but then checks for a blank realm to use as a default.
Original code (in get_basic_credentials):
if (exists $self->{'basic_authentication'}{$host_port}{$realm}) {
return @{ $self->{'basic_authentication'}{$host_port}{$realm} };
}
Updated code:
if (exists $self->{'basic_authentication'}{$host_port}{$realm}) {
return @{ $self->{'basic_authentication'}{$host_port}{$realm} };
} elsif (exists $self->{'basic_authentication'}{$host_port}{''}) {
return @{ $self->{'basic_authentication'}{$host_port}{''} };
}
More readable version (I think):
for ($realm, '')
{
if (exists $self->{'basic_authentication'}{$host_port}{$_}) {
return @{ $self->{'basic_authentication'}{$host_port}{$_} };
}
}
The blank realm ('') could be replaced by some other default ('*', for instance). If you think this would be a good addition, please add it. By the way, what does it take to officially become an "author" of this module?
Thanks,
Jaime Bellmyer