diff options
author | franck cuny <franck@lumberjaph.net> | 2009-07-02 15:17:21 +0200 |
---|---|---|
committer | franck cuny <franck@lumberjaph.net> | 2009-07-02 15:17:21 +0200 |
commit | b829c9e76a7a2611df953680845704abe99da836 (patch) | |
tree | 5f692589513c01fdd7ce3dfbb26b8658a70febe5 | |
parent | test encoding (diff) | |
download | moosex-useragent-b829c9e76a7a2611df953680845704abe99da836.tar.gz |
add LWPx::ParanoidAgent as new agent
-rw-r--r-- | lib/MooseX/UserAgent/Paranoid.pm | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/MooseX/UserAgent/Paranoid.pm b/lib/MooseX/UserAgent/Paranoid.pm new file mode 100644 index 0000000..61dab94 --- /dev/null +++ b/lib/MooseX/UserAgent/Paranoid.pm @@ -0,0 +1,32 @@ +package MooseX::UserAgent::Paranoid; + +use URI; +use HTTP::Request; +use HTTP::Response; +use LWPx::ParanoidAgent; + +use Moose::Role; +with qw/ + MooseX::UserAgent::Config + MooseX::UserAgent::Content + MooseX::UserAgent::Cache + /; + +has _LWPLIB => ( isa => 'Str', is => 'ro', default => 'LWPx::ParanoidAgent' ); + +sub fetch { + my ( $self, $url ) = @_; + + my $req = HTTP::Request->new( GET => URI->new($url) ); + + $req->header( 'Accept-Encoding', 'gzip' ); + my $last_modified = $self->get_ua_cache($url); + $req->header( 'If-Modified-Since' => $last_modified ) + if $last_modified; + + my $res = $self->agent->request($req); + $self->store_ua_cache( $url, $res ); + $res; +} + +1; |