README
1NAME
2 Plack::Middleware::Throttle - A Plack Middleware for rate-limiting
3 incoming HTTP requests.
4
5SYNOPSIS
6 my $handler = builder {
7 enable "Throttle::Hourly",
8 max => 2,
9 backend => Plack::Middleware::Throttle::Backend::Hash->new(),
10 path => qr{^/api};
11 sub { [ '200', [ 'Content-Type' => 'text/html' ], ['hello world'] ] };
12 };
13
14DESCRIPTION
15 This is a "Plack" middleware that provides logic for rate-limiting
16 incoming HTTP requests to Rack applications.
17
18 This middleware provides three ways to handle throttling on incoming
19 requests :
20
21 Hourly
22 How many requests an host can do in one hour. The counter is reseted
23 each hour.
24
25 Daily
26 How many requets an host can do in one hour. The counter is reseted
27 each day.
28
29 Interval
30 Which interval of time an host must respect between two request.
31
32OPTIONS
33 code
34 HTTP code returned in the response when the limit have been
35 exceeded. By default 503.
36
37 message
38 HTTP message returned in the response when the limit have been
39 exceeded. By defaylt "Over rate limit".
40
41 backend
42 A cache object to store sessions informations.
43
44 backend => Redis->new(server => '127.0.0.1:6379');
45
46 or
47
48 backend => Cache::Memcached->new(servers => ["10.0.0.15:11211", "10.0.0.15:11212"]);
49
50 The cache object must implement get, set and incr methods. By
51 default, you can use "Plack::Middleware::Throttle::Backend::Hash".
52
53 By default, if no backend is specified,
54 Plack::Middleware::Throttle::Backend::Hash is used.
55
56 key_prefix
57 Key to prefix sessions entry in the cache.
58
59 path
60 URL pattern or a callback to match request to throttle. If no path
61 is specified, the whole application will be throttled.
62
63 white_list
64 An arrayref of hosts to put in a white list.
65
66 black_list
67 An arrayref of hosts to put in a black list.
68
69AUTHOR
70 franck cuny <franck@lumberjaph.net>
71
72SEE ALSO
73LICENSE
74 This library is free software; you can redistribute it and/or modify it
75 under the same terms as Perl itself.
76
77