Skip Menu |

This queue is for tickets about the LWP-UserAgent-POE CPAN distribution.

Report information
The Basics
Id: 41164
Status: resolved
Priority: 0/
Queue: LWP-UserAgent-POE

People
Owner: Nobody in particular
Requestors: MMIMS [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.01
Fixed in: (no value)



Subject: [Patch] Does not honor LWP::UserAgent defaults
LWP::UesrAgent::POE is not quite a drop-in replacement for LWP::UserAgent as documented as it does not use the same defaults. The attached patch, with tests, corrects this discrepancy. -Marc
Subject: lwp-ua-poe.patch
diff --git a/POE.pm b/POE.pm index ecd091e..49ef7a6 100644 --- a/POE.pm +++ b/POE.pm @@ -25,6 +25,13 @@ sub new { my $self = bless { await_id => 0, poco_alias => "lwp_useragent_poe_http_client_poco", + + # LWP::UserAgent defaults + agent => "libwww-perl/$LWP::UserAgent::VERSION", + max_redirect => 7, + parse_head => 1, + requests_redirectable => [qw/GET HEAD/], + timeout => 180, %options, }, $class; diff --git a/t/lwp_useragent_compat.t b/t/lwp_useragent_compat.t new file mode 100644 index 0000000..690c75a --- /dev/null +++ b/t/lwp_useragent_compat.t @@ -0,0 +1,29 @@ +use warnings; +use strict; +use Test::More; + +use LWP::UserAgent::POE; + +my @defaults = qw/ + agent + from + conn_cache + cookie_jar + default_headers + max_size + max_redirect + parse_head + protocols_allowed + protocols_forbidden + requests_redirectable + timeout +/; + +plan tests => scalar @defaults; + +my $ua = LWP::UserAgent->new; +my $uap = LWP::UserAgent::POE->new; + +is_deeply $uap->$_, $ua->$_, $_ for @defaults; + +POE::Kernel->run;
On Sun Nov 23 14:42:17 2008, MMIMS wrote: Show quoted text
> LWP::UesrAgent::POE is not quite a drop-in replacement for > LWP::UserAgent as documented as it does not use the same defaults. > > The attached patch, with tests, corrects this discrepancy.
My patch was tested on a system with LWP::UserAgent v5.813 installed. It failed horribly when tested on a system with v5.819 and with v5.820. In fact, I've been unable to get LWP::UserAgent::POE to follow redirects since upgrading LWP::UserAgent. I wanted to warn you about the patch before you invested any time in it. -Marc
On Mon Nov 24 14:53:10 2008, MMIMS wrote: Show quoted text
> My patch was tested on a system with LWP::UserAgent v5.813 installed. It > failed horribly when tested on a system with v5.819 and with v5.820. > > In fact, I've been unable to get LWP::UserAgent::POE to follow redirects > since upgrading LWP::UserAgent.
Redirects work with LWP::UserAgent v5.814, but not with v5.819.
Subject: [Tests] Basic auth failure with LWP::UserAgent::POE with LWP::UserAgent ver > 5.814
RT-Send-CC: cthom [...] cpan.org
The attached tests demonstrate the problem with basic authentication. Both tests pass when LWP::UserAgent version <= 5.814 is installed. The LWP::UserAgent::POE test fails when LWP::UserAgent version > 5.814 is installed.
#!/usr/bin/perl use warnings; use strict; use LWP::UserAgent::POE; use Net::Netrc; use Test::More tests => 1; my ($user_id, $password) = Net::Netrc->lookup('twitter')->lpa; my $apiurl = 'http://twitter.com'; my $netloc = 'twitter.com:80'; my $realm = 'Twitter API'; my $agent = LWP::UserAgent::POE->new; $agent->credentials($netloc, $realm, $user_id, $password); sub friends { my $url = $apiurl . '/statuses/friends.json'; my $req = $agent->get($url); } my $res = friends; is $res->code, 200, 'success'; POE::Kernel->run; exit 0;
#!/usr/bin/perl use warnings; use strict; use LWP::UserAgent; use Net::Netrc; use Test::More tests => 1; my ($user_id, $password) = Net::Netrc->lookup('twitter')->lpa; my $apiurl = 'http://twitter.com'; my $netloc = 'twitter.com:80'; my $realm = 'Twitter API'; my $agent = LWP::UserAgent->new; $agent->credentials($netloc, $realm, $user_id, $password); sub friends { my $url = $apiurl . '/statuses/friends.json'; my $req = $agent->get($url); } my $res = friends; is $res->code, 200, 'success'; exit 0;
Fixed in LWP::UserAgent::POE 0.02 by adding prepare_request() to simple_request(). Thanks for the bug report and patches! -- Mike