Package dev.gmitch215.bytebox.binding
Interface RateLimit
- All Superinterfaces:
org.teavm.jso.JSObject
public interface RateLimit
extends org.teavm.jso.JSObject
A rate limiting binding. Declared with
rateLimit(), named RATELIMIT by default.
The limit and period come from the Wrangler configuration rather than from the call, so this surface is one question: has this key had its allowance.
Counting is per colo rather than global, so the effective limit across the network is higher than the configured one.
if (!env.rateLimit().allow(request.getHeaders().get("cf-connecting-ip"))) {
return Bytebox.response("slow down", 429);
}
- Since:
- 1.0.0
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceWhether a key was within its allowance. -
Method Summary
Modifier and TypeMethodDescriptiondefault booleanConsumes one unit of a key's allowance.org.teavm.jso.core.JSPromise<RateLimit.Outcome> Methods inherited from interface org.teavm.jso.JSObject
cast
-
Method Details
-
allow
Consumes one unit of a key's allowance.- Parameters:
key- what to count against, such as an IP or a user id- Returns:
- whether the request is within the limit
-
limit
-