Skip to content

Commit

Permalink
add new middleware: DoNotTrack
Browse files Browse the repository at this point in the history
Signed-off-by: franck cuny <[email protected]>
  • Loading branch information
fcuny committed Jul 26, 2011
1 parent b567990 commit f6411d1
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/Net/HTTP/Spore/Middleware/DoNotTrack.pm
Original file line number Diff line number Diff line change
@@ -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/>.
24 changes: 24 additions & 0 deletions t/spore-middleware/x-do-not-track.t
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit f6411d1

Please sign in to comment.