Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var (
ErrRateLimitExceeded = errors.New("rate limit exceeded, please try again later")
)
Functions ¶
func ClearHeaders ¶ added in v0.28.0
ClearHeaders removes the rate limit headers ApplyLimit set, for a response that refuses the request for another reason, such as an exhausted LLM budget, which they would contradict.
Types ¶
type RateLimiter ¶
type RateLimiter struct {
// contains filtered or unexported fields
}
RateLimiter limits the number of HTTP requests per second a user can make. It tracks limits for unauthenticated and authenticated users separately: - Authenticated requests are tracked by user ID or name. - SCIM connection requests are tracked by connection ID, at the authenticated rate. - Unauthenticated requests are tracked by IP address. - Admins and internal tunnel bridge and peer requests are exempt from rate limiting.
func New ¶
func New(opts Options) (*RateLimiter, error)
func (*RateLimiter) ApplyLimit ¶
func (l *RateLimiter) ApplyLimit(u user.Info, rw http.ResponseWriter, req *http.Request) error
ApplyLimit applies the user's rate limit to the request, sets the rate limit headers, and returns a ErrRateLimitExceeded error if the limit has been exceeded. It returns nil if the user is exempt from rate limiting or if the user has not exceeded their limit.