Permalink
Browse files

Send a default UserAgent header.

  • Loading branch information...
omega committed May 25, 2009
1 parent d1e258a commit d56862434eea154718c89f21140f2262dec0f0fc
Showing with 33 additions and 3 deletions.
  1. +4 −0 Changes
  2. +2 −0 TODO
  3. +2 −2 lib/WWW/Curl/Simple.pm
  4. +15 −0 lib/WWW/Curl/Simple/Request.pm
  5. +10 −1 t/10.usage.single.t
View
@@ -1,4 +1,8 @@
Revision history for WWW-Curl-Simple
+0.04 2009-05-25 13:06:00+0200
+ Set a default UserAgent header, since some services seem to require a
+ UserAgent header.
+
0.03 2009-04-20 09:32:00+0200
Bump version.
View
2 TODO
@@ -0,0 +1,2 @@
+- Add posibility for changing $req->agent to WWW::Curl::Simple somehow
+
View
@@ -20,7 +20,7 @@ WWW::Curl::Simple - A simpler interface to WWW::Curl
=head1 VERSION
-Version 0.02
+Version 0.04
=head1 SYNOPSIS
@@ -37,7 +37,7 @@ Perhaps a little code snippet.
=cut
-our $VERSION = '0.03';
+our $VERSION = '0.04';
=head3 request($req)
@@ -22,6 +22,20 @@ use namespace::clean -except => 'meta';
=head1 INTERFACE
+=head2 ATTRIBUTES
+
+=head3 agent
+
+A String that will be sent as the user-agent string. Defaults to
+
+=cut
+
+has 'agent' => (is => 'rw', isa => 'Str', required => 0, lazy_build => 1);
+
+sub _build_agent {
+ return "WWW::Curl::Simple/" . $WWW::Curl::Simple::VERSION;
+}
+
=head2 METHODS
=head3 body
@@ -66,6 +80,7 @@ sub _build_easy {
my $curl = new WWW::Curl::Easy;
$curl->setopt(CURLOPT_NOPROGRESS,1);
+ $curl->setopt(CURLOPT_USERAGENT, $self->agent);
my $url = $req->uri->as_string;
$curl->setopt(CURLOPT_URL, $url);
View
@@ -1,7 +1,7 @@
#!/usr/bin/perl -w
use strict;
-use Test::More tests => 10;
+use Test::More tests => 14;
use WWW::Curl::Simple;
@@ -35,4 +35,13 @@ my $curl = WWW::Curl::Simple->new();
}
isa_ok($res->request, "HTTP::Request");
+}
+
+{
+ my $res = $curl->request(HTTP::Request->new(GET => 'http://bilder.abcsok.no/search/rss?rows=1&q=jens'));
+ isa_ok($res, "HTTP::Response");
+ ok($res->is_success, "request suceeded");
+ like($res->content, qr/bilder/);
+ isa_ok($res->request, "HTTP::Request");
+
}

0 comments on commit d568624

Please sign in to comment.