gflare/middleware/rate_limit

Types

pub type RateLimitConfig {
  RateLimitConfig(
    window_ms: Int,
    max_requests: Int,
    key_fn: fn(request.HttpRequest) -> String,
    message: String,
  )
}

Constructors

  • RateLimitConfig(
      window_ms: Int,
      max_requests: Int,
      key_fn: fn(request.HttpRequest) -> String,
      message: String,
    )
pub type RateLimitResult {
  Allowed(remaining: Int)
  Denied(retry_after: Int)
}

Constructors

  • Allowed(remaining: Int)
  • Denied(retry_after: Int)

Values

pub fn check_rate_limit(
  config: RateLimitConfig,
  namespace: kv.Kv,
  key: String,
) -> promise.Promise(RateLimitResult)
pub fn custom(
  config: RateLimitConfig,
  namespace: kv.Kv,
) -> router.Middleware
pub fn get_client_ip(request: request.HttpRequest) -> String
pub fn kv_middleware(
  config: RateLimitConfig,
  namespace: kv.Kv,
) -> router.Middleware
pub fn permissive(namespace: kv.Kv) -> router.Middleware
pub fn strict(namespace: kv.Kv) -> router.Middleware
Search Document