Re: Problems setting headers for a request
Gisle Aas (gisle@activestate.com)
17 Jan 2001 10:30:47 -0800
"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