NAME
PAGI::App::Throttle - Rate-limited request processing
SYNOPSIS
use PAGI::App::Throttle;
my $app = PAGI::App::Throttle->new(
app => $inner_app,
rate => 10, # requests per second
burst => 20, # max burst
key_for => sub { $_[0]->{client}[0] }, # key by IP
)->to_app;
DESCRIPTION
Token bucket rate limiting for PAGI applications. Limits requests based on configurable rate and burst settings.
OPTIONS
app- The inner application to rate limitrate- Requests per second (default: 10)burst- Maximum burst size (default: rate)key_for- Coderef to extract rate limit key from scopeon_limit- Custom handler for rate-limited requestsheaders- Add rate limit headers (default: 1)
RATE LIMIT HEADERS
When enabled, adds these headers:
X-RateLimit-Limit - Maximum requests allowed
X-RateLimit-Remaining - Requests remaining
X-RateLimit-Reset - Unix timestamp when limit resets
CLASS METHODS
reset($key)
Reset the token bucket for a specific key.
reset_all()
Reset all token buckets.
info($key)
Get bucket info (tokens, last_time) for a key.