Class RateLimiter

Nested Relationships

Nested Types

Class Documentation

class RateLimiter

Token-bucket-based HTTP rate limiter.

Provides two-layer rate limiting:

  • Global bucket: limits total request rate across all clients

  • Per-client bucket: limits request rate per client IP

Thread-safe for use from cpp-httplib’s worker thread pool.

Public Functions

explicit RateLimiter(const RateLimitConfig &config)
RateLimitResult check(const std::string &client_ip, const std::string &path)

Check if a request is allowed and return rate limit info.

void cleanup_stale_clients()

Remove tracking entries for clients that have been idle too long.

inline bool is_enabled() const

Check if rate limiting is enabled.

Public Static Functions

static void apply_headers(const RateLimitResult &result, httplib::Response &res)

Set rate limit response headers on the HTTP response.

static void apply_rejection(const RateLimitResult &result, httplib::Response &res)

Set 429 rejection response with SOVD-compliant error body.