diff options
author | franck cuny <franck@lumberjaph.net> | 2011-07-22 16:42:14 +0200 |
---|---|---|
committer | franck cuny <franck@lumberjaph.net> | 2011-07-26 13:21:02 +0200 |
commit | f6411d1ba49db638ed63f831a8e6f87af0e2f9ff (patch) | |
tree | f9e2cfdf41246e9c5bc69ac90cbcfb34664d8098 | |
parent | add some changes (diff) | |
download | net-http-spore-f6411d1ba49db638ed63f831a8e6f87af0e2f9ff.tar.gz |
add new middleware: DoNotTrack
Signed-off-by: franck cuny <franck@lumberjaph.net>
-rw-r--r-- | lib/Net/HTTP/Spore/Middleware/DoNotTrack.pm | 22 | ||||
-rw-r--r-- | t/spore-middleware/x-do-not-track.t | 24 |
2 files changed, 46 insertions, 0 deletions
diff --git a/lib/Net/HTTP/Spore/Middleware/DoNotTrack.pm b/lib/Net/HTTP/Spore/Middleware/DoNotTrack.pm new file mode 100644 index 0000000..9df053a --- /dev/null +++ b/lib/Net/HTTP/Spore/Middleware/DoNotTrack.pm @@ -0,0 +1,22 @@ +package Net::HTTP::Spore::Middleware::DoNotTrack; + +# ABSTRACT: add a new header to not track + +use Moose; +extends 'Net::HTTP::Spore::Middleware'; + +sub call { + my ($self, $req) = @_; + $req->header('x-do-not-track' => 1); +} + +1; + +=head1 SYNOPSIS + + my $client = Net::HTTP::Spore->new_from_spec('twitter.json'); + $client->enable('Runtime'); + +=head1 DESCRIPTION + +Add a header B<x-do-not-track> to your requests. For more details see L<http://donottrack.us/>. diff --git a/t/spore-middleware/x-do-not-track.t b/t/spore-middleware/x-do-not-track.t new file mode 100644 index 0000000..8082385 --- /dev/null +++ b/t/spore-middleware/x-do-not-track.t @@ -0,0 +1,24 @@ +use strict; +use warnings; + +use Test::More; +use Net::HTTP::Spore; + +my $mock_server = { + '/show' => sub { + my $req = shift; + ok $req->header('x-do-not-track'); + $req->new_response( 200, [ 'Content-Type' => 'text/plan' ], 'ok'); + }, +}; + +ok my $client = + Net::HTTP::Spore->new_from_spec( 't/specs/api.json', + base_url => 'http://localhost:5984' ); + +$client->enable('DoNotTrack'); +$client->enable('Mock', tests => $mock_server); + +my $res = $client->get_info(); + +done_testing; |