hono-rate-limiter
Version:
Rate limit middleware for Hono.
29 lines (28 loc) • 1.42 kB
TypeScript
import type { Context } from "hono";
import type { RateLimitInfo } from "./types";
/**
* Sets `RateLimit-*`` headers based on the sixth draft of the IETF specification.
* See https://datatracker.ietf.org/doc/html/draft-ietf-httpapi-ratelimit-headers-06.
*
* @param context {Context} - The hono context object to set headers on.
* @param info {RateLimitInfo} - The rate limit info, used to set the headers.
* @param windowMs {number} - The window length.
*/
export declare const setDraft6Headers: (context: Context, info: RateLimitInfo, windowMs: number) => void;
/**
* Sets `RateLimit` & `RateLimit-Policy` headers based on the seventh draft of the spec.
* See https://datatracker.ietf.org/doc/html/draft-ietf-httpapi-ratelimit-headers-07.
*
* @param context {Context} - The hono context object to set headers on.
* @param info {RateLimitInfo} - The rate limit info, used to set the headers.
* @param windowMs {number} - The window length.
*/
export declare const setDraft7Headers: (context: Context, info: RateLimitInfo, windowMs: number) => void;
/**
* Sets the `Retry-After` header.
*
* @param context {Context} - The hono context object to set headers on.
* @param info {RateLimitInfo} - The rate limit info, used to set the headers.
* @param windowMs {number} - The window length.
*/
export declare const setRetryAfterHeader: (context: Context, info: RateLimitInfo, windowMs: number) => void;