From 2a68ed3d0138827f4fed8a3520f7859493da4e1b Mon Sep 17 00:00:00 2001 From: franck cuny Date: Wed, 31 Mar 2010 22:30:23 +0200 Subject: import old Plack::Middleware::APIRateLimit (renamed as miyagawa's suggestion) and stole API from rack::throttle --- t/01_basic.t | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 t/01_basic.t (limited to 't/01_basic.t') diff --git a/t/01_basic.t b/t/01_basic.t new file mode 100644 index 0000000..31a4e98 --- /dev/null +++ b/t/01_basic.t @@ -0,0 +1,35 @@ +use strict; +use warnings; +use Test::More; + +use Plack::Test; +use Plack::Builder; +use HTTP::Request::Common; +use Plack::Middleware::Throttle::Backend::Hash; + +my $handler = builder { + enable "Throttle::Hourly", + max => 2, + backend => Plack::Middleware::Throttle::Backend::Hash->new(); + sub { [ '200', [ 'Content-Type' => 'text/html' ], ['hello world'] ] }; +}; + +test_psgi + app => $handler, + client => sub { + my $cb = shift; + { + for ( 1 .. 2 ) { + my $req = GET "http://localhost/"; + my $res = $cb->($req); + is $res->code, 200, 'http response is 200'; + ok $res->headers('X-RateLimit-Limit'), 'header ratelimit'; + } + my $req = GET "http://localhost/"; + my $res = $cb->($req); + is $res->code, 503, 'http response is 503'; + ok $res->headers('X-RateLimit-Reset'), 'header reset'; + } + }; + +done_testing; -- cgit v1.2.3