Documentation
¶
Overview ¶
Package viewerlimit rate-limits the portal's public share viewer. It wraps the shared ratelimit.HTTPLimiter with the viewer's defaults so the public surface gets the same spoof-resistant, trusted-proxy-aware client attribution and global-saturation guard as the OAuth endpoints (#904).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
Config configures the public portal viewer's rate limiter. It is an alias for the shared ratelimit.Config so there is one config shape and one token-bucket implementation across the platform. Client-IP attribution is supplied separately as a ratelimit.Resolver (see New) rather than baked into this config, mirroring how the OAuth endpoints compose the two.
type RateLimiter ¶
type RateLimiter struct {
// contains filtered or unexported fields
}
RateLimiter provides two-layer rate limiting for the public portal viewer: a per-client-IP bucket for fairness and a global backstop that bounds total throughput regardless of client attribution. It delegates both to the shared ratelimit.HTTPLimiter. The public viewer serves cached asset blobs to unauthenticated callers, so an attacker who can mint unlimited per-IP buckets by rotating a spoofed X-Forwarded-For would otherwise defeat the per-IP limit outright; the resolver closes that hole and the global bucket bounds the overflow.
func New ¶
func New(cfg Config, resolver *ratelimit.Resolver) *RateLimiter
New creates a rate limiter from config and a client-IP resolver. A nil resolver yields the safe trust-none default: the direct peer address is used and X-Forwarded-For is ignored (matching ratelimit.NewResolver(nil), which never errors on nil input). Callers that trust a proxy topology build the resolver from a trusted-proxy CIDR list and pass it in.
func (*RateLimiter) Allow ¶
func (rl *RateLimiter) Allow(r *http.Request) bool
Allow reports whether the request should be admitted, consuming a token from both the per-IP and global buckets on admission. Client-IP attribution is delegated to the resolver, so a spoofed X-Forwarded-For no longer mints a fresh per-IP bucket.
func (*RateLimiter) Close ¶
func (rl *RateLimiter) Close()
Close stops the background cleanup goroutines.
func (*RateLimiter) Middleware ¶
func (rl *RateLimiter) Middleware(next http.Handler) http.Handler
Middleware wraps an http.Handler with rate limiting.