Documentation ¶
Index ¶
- type RateLimit
- func (RateLimit) CaddyModule() caddy.ModuleInfo
- func (rl *RateLimit) Cleanup() error
- func (rl *RateLimit) Provision(ctx caddy.Context) (err error)
- func (rl *RateLimit) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp.Handler) error
- func (rl *RateLimit) UnmarshalCaddyfile(d *caddyfile.Dispenser) (err error)
- func (rl *RateLimit) Validate() error
- type Var
- type Zone
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type RateLimit ¶
type RateLimit struct { // The variable used to differentiate one client from another. // // Currently supported variables: // // - `{path.<var>}` // - `{query.<var>}` // - `{header.<VAR>}` // - `{cookie.<var>}` // - `{body.<var>}` (requires the [requestbodyvar](https://github.com/RussellLuo/caddy-ext/tree/master/requestbodyvar) extension) // - `{remote.host}` (ignores the `X-Forwarded-For` header) // - `{remote.port}` // - `{remote.ip}` (prefers the first IP in the `X-Forwarded-For` header) // - `{remote.host_prefix.<bits>}` (CIDR block version of `{remote.host}`) // - `{remote.ip_prefix.<bits>}` (CIDR block version of `{remote.ip}`) Key string `json:"key,omitempty"` // The request rate limit (per key value) specified in requests // per second (r/s) or requests per minute (r/m). Rate string `json:"rate,omitempty"` // The size (i.e. the number of key values) of the LRU zone that // keeps states of these key values. Defaults to 10,000. ZoneSize int `json:"zone_size,omitempty"` // The HTTP status code of the response when a client exceeds the rate. // Defaults to 429 (Too Many Requests). RejectStatusCode int `json:"reject_status,omitempty"` // contains filtered or unexported fields }
RateLimit implements a handler for rate-limiting.
If a client exceeds the rate limit, an HTTP error with status `<reject_status>` will be returned. This error can be handled using the conventional error handlers. See [handle_errors](https://caddyserver.com/docs/caddyfile/directives/handle_errors) for how to set up error handlers.
func (RateLimit) CaddyModule ¶
func (RateLimit) CaddyModule() caddy.ModuleInfo
CaddyModule returns the Caddy module information.
func (*RateLimit) ServeHTTP ¶
func (rl *RateLimit) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp.Handler) error
ServeHTTP implements caddyhttp.MiddlewareHandler.
func (*RateLimit) UnmarshalCaddyfile ¶
type Var ¶
func ParseVar ¶
ParseVar transforms shorthand variables into Caddy-style placeholders.
Examples for shorthand variables:
- `{path.<var>}` - `{query.<var>}` - `{header.<VAR>}` - `{cookie.<var>}` - `{body.<var>}` - `{remote.host}` - `{remote.port}` - `{remote.ip}` - `{remote.host_prefix.<bits>}` - `{remote.ip_prefix.<bits>}`
type Zone ¶
type Zone struct {
// contains filtered or unexported fields
}