Subject: | perl-5.18.0 + LWP-6.05 fails to send User-Agent Header |
Date: | Mon, 22 Jul 2013 12:07:37 -0500 |
To: | " bug-libwww-perl" [...] rt.cpan.org |
From: | David Favor <david [...] davidfavor.com> |
Very ugly.
Output from my test code.
./lwp-bug
using: perl-5.18.0 + LWP-6.05
agent: expected : Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.71 Safari/537.36
agent: from LWP : libwww-perl/6.05
agent: live check: libwww-perl/6.05
This code checks ->_agent + does a live check against http://WhatsMyUserAgent.com and returns results.
Tried with several different perls.
Code follows.
Show quoted text
_______
#!/usr/bin/env perl
# author : David Favor @ http://DavidFavor.com
# purpose: Illustrate LWP fails to send User-Agent Header
use strict;
use warnings;
use Carp qw/confess/;
use Config;
use LWP::UserAgent;
use HTTP::Request::Common qw(GET POST);
use Data::Dumper;
$Data::Dumper::Useqq = 1;
$Data::Dumper::Terse = 1;
$Data::Dumper::Sortkeys = 1;
my $bua = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.71 Safari/537.36';
my $perlver = $Config{api_versionstring};
my $lwpver = $LWP::VERSION;
print "using: perl-$perlver + LWP-$lwpver\n";
my $lwp = new LWP::UserAgent;
$lwp->agent ($bua);
my $url = 'http://WhatsMyUserAgent.com/';
my $req = GET $url;
my $res = $lwp->request($req);
confess("Unable to GET($url): ", $res->status_line) unless $res->is_success;
my $sua = $res->content;
$sua =~ s/^.+<span id="body_lbUserAgent">//o;
$sua =~ s/<span.+$//o;
print "agent: expected : ", $bua, "\n";
print "agent: from LWP : ", $lwp->_agent, "\n";
print "agent: live check: ", $lwp->_agent, "\n";
--
Love Living Well Doing What You Love?
http://DavidFavor.com/bb can help!