in reply to User-Agent in LWP::UserAgent
Internally, ->agent is controlling the default header User-Agent. Default headers effect the creation of new requests, which is why your first request takes the adjusted agent string. When following redirects, the previous request is cloned and then adjusted. No default headers are applied.
The request_preprepare handler is still run for the cloned requests. It is given the request as its first parameter. Changing the User-Agent header in that handler should give you the results you expected.
$ua->add_handler( request_preprepare => sub { my ($req) = @_; $req->header('User-Agent', "TEST $ctr"); print "User-Agent: ", $req->header('User-Agent'), "\n"; $ctr++; }, );
|
|---|