xmpp-httpx - v0.11.0
    Preparing search index...

    Interface RateLimitOptions

    Per-requester rate limiting: a token bucket keyed by bare JID, wrapping a handler.

    Why a handler wrapper rather than an authorize hook, which is where the roadmap put it: AuthorizeFn can only say yes or no, and the server turns a no into forbidden. A throttled client should be told to slow down, not that it is not allowed — so this returns a real 429 with Retry-After, which a client can act on. It costs no more: the server hands the handler an unread body stream, so refusing here still avoids both the origin call and reading the request.

    Keyed on the bare JID because resources are cheap to mint: limiting alice@example.org/laptop separately from /phone would let one account multiply its own quota at will.

    Browser-safe: the only ambient dependency is a clock, and that is injectable.

    interface RateLimitOptions {
        burst?: number;
        maxTracked?: number;
        now?: () => number;
        onLimited?: (from: string, retryAfterSeconds: number) => void;
        ratePerSecond: number;
    }
    Index
    burst?: number

    Requests allowed in a burst. Defaults to ceil(ratePerSecond), min 1.

    maxTracked?: number

    Cap on how many JIDs are tracked at once, so a flood of distinct senders cannot grow the map without bound. When full, the least recently seen entry is dropped — which at worst gives that sender a fresh bucket, never an error. Default 10 000.

    now?: () => number

    Injectable clock in milliseconds, for tests.

    onLimited?: (from: string, retryAfterSeconds: number) => void

    Called for each refused request, for logging and metrics.

    ratePerSecond: number

    Sustained requests per second, per bare JID. May be fractional.