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

Re: Problems setting headers for a request

Thread Previous
From:
Gisle Aas
Date:
January 17, 2001 10:31
Subject:
Re: Problems setting headers for a request
Message ID:
lr8zoaav54.fsf@caliper.ActiveState.com
"Tristan Greaves" <tgreaves@argogroup.com> writes:

> The aim of the following code is to allow the HTTP headers for
> a request to be set.  At the moment, it's just trying
> User-Agent, but this would be extended to allow other, perhaps
> custom, headers.
> 
> <--begin code fragment-->
>         my $ua = LWP::UserAgent->new();
>         my $req = HTTP::Request->new(GET => $url);
>         $req->header(User_Agent => 'FooBarBrowser 1.0');
> 
>         # Prove that we've actually set the headers...
>         print $req->headers_as_string();
>         print "<---ENDHEADERS--->\n";
> 
>         # Perform request...
> 
>         my $response = $ua->request($req);
> <--end code fragment-->
> 
> However, this doesn't appear to work - The User-Agent string does
> not appear to be set, according to the logs at the "other end".
> 
> I'm aware of the $ua->agent() system (which works!!), but I want
> to use the above method to allow custom ones to be added.
> 
> So, what's the problem?

The problem is that LWP::UserAgent unconditionally overrides the
request User-Agent setting with what it finds in $ua->agent.  This
bug is already registered in http://sourceforge.net/bugs/?group_id=14630

Regards,
Gisle

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About