summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfranck cuny <franck@lumberjaph.net>2010-04-28 09:18:39 +0200
committerfranck cuny <franck@lumberjaph.net>2010-04-28 09:18:39 +0200
commit22a2333a63dc7703c93342ef9824b7d22e716316 (patch)
tree0df06881ef313997bfdc4dd07edc374862c1c641
parentPOD fix (diff)
downloadplack-middleware-throttle-master.tar.gz
Checking in changes prior to tagging of version 0.01. Changelog diff is:master
Diffstat (limited to '')
-rw-r--r--.gitignore2
-rw-r--r--Makefile.PL7
-rw-r--r--README5
-rw-r--r--lib/Plack/Middleware/Throttle.pm6
-rw-r--r--t/05_filter_path.t6
5 files changed, 18 insertions, 8 deletions
diff --git a/.gitignore b/.gitignore
index c38068c..53d7b16 100644
--- a/.gitignore
+++ b/.gitignore
@@ -9,3 +9,5 @@ Makefile.old
nytprof.out
MANIFEST.bak
*.sw[po]
+.prove
+MANIFEST.SKIP
diff --git a/Makefile.PL b/Makefile.PL
index 0543aa0..0a5d9f4 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -3,11 +3,16 @@ name 'Plack-Middleware-Throttle';
all_from 'lib/Plack/Middleware/Throttle.pm';
readme_from 'lib/Plack/Middleware/Throttle.pm';
-# requires '';
+requires 'Plack';
+requires 'Moose';
+requires 'Scalar::Util';
+requires 'HTTP::Request::Common';
+requires 'DateTime';
tests 't/*.t';
build_requires 'Test::More';
+test_requires 'Test::Requires';
use_test_base;
auto_include;
#auto_include_deps;
diff --git a/README b/README
index 9da20a3..60e63f5 100644
--- a/README
+++ b/README
@@ -7,7 +7,7 @@ SYNOPSIS
enable "Throttle::Hourly",
max => 2,
backend => Plack::Middleware::Throttle::Backend::Hash->new(),
- path => qr{^/foo};
+ path => qr{^/api};
sub { [ '200', [ 'Content-Type' => 'text/html' ], ['hello world'] ] };
};
@@ -50,6 +50,9 @@ OPTIONS
The cache object must implement get, set and incr methods. By
default, you can use "Plack::Middleware::Throttle::Backend::Hash".
+ By default, if no backend is specified,
+ Plack::Middleware::Throttle::Backend::Hash is used.
+
key_prefix
Key to prefix sessions entry in the cache.
diff --git a/lib/Plack/Middleware/Throttle.pm b/lib/Plack/Middleware/Throttle.pm
index 3100325..d3a8fd1 100644
--- a/lib/Plack/Middleware/Throttle.pm
+++ b/lib/Plack/Middleware/Throttle.pm
@@ -98,7 +98,7 @@ sub is_black_listed {
sub path_is_throttled {
my ( $self, $env ) = @_;
- return 0 if !$self->has_path;
+ return 1 if !$self->has_path;
my $path_match = $self->path;
my $path = $env->{PATH_INFO};
@@ -106,7 +106,7 @@ sub path_is_throttled {
my $matched = 'CODE' eq ref $path_match ? $path_match->($_) : $_ =~ $path_match;
$matched ? return 1 : return 0;
}
- return 0;
+ return 1;
}
sub forbiden {
@@ -161,7 +161,7 @@ Plack::Middleware::Throttle - A Plack Middleware for rate-limiting incoming HTTP
enable "Throttle::Hourly",
max => 2,
backend => Plack::Middleware::Throttle::Backend::Hash->new(),
- path => qr{^/foo};
+ path => qr{^/api};
sub { [ '200', [ 'Content-Type' => 'text/html' ], ['hello world'] ] };
};
diff --git a/t/05_filter_path.t b/t/05_filter_path.t
index 1be3706..fa86608 100644
--- a/t/05_filter_path.t
+++ b/t/05_filter_path.t
@@ -11,7 +11,7 @@ my $handler = builder {
enable "Throttle::Hourly",
max => 1,
backend => Plack::Middleware::Throttle::Backend::Hash->new(),
- path => qr{^/foo};
+ path => qr{^/api};
sub { [ '200', [ 'Content-Type' => 'text/html' ], ['hello world'] ] };
};
@@ -26,11 +26,11 @@ test_psgi
is $res->content, 'hello world', 'content is valid';
ok !$res->header('X-RateLimit-Limit'), 'no header ratelimit';
}
- my $req = GET "http://localhost/foo";
+ my $req = GET "http://localhost/api";
my $res = $cb->($req);
is $res->content, 'hello world', 'content is valid';
ok $res->header('X-RateLimit-Limit'), 'header ratelimit';
- $req = GET "http://localhost/foo";
+ $req = GET "http://localhost/api";
$res = $cb->($req);
is $res->code, 503, 'rate limit exceeded';
}