Documentation
¶
Overview ¶
Package middleware provides HTTP middleware for the proxy.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetClientIP ¶
GetClientIP extracts the client IP from an HTTP request.
Types ¶
type RateLimiter ¶
type RateLimiter struct {
// contains filtered or unexported fields
}
RateLimiter provides per-client IP rate limiting.
func NewRateLimiter ¶
func NewRateLimiter(rate int, window time.Duration) *RateLimiter
NewRateLimiter creates a new rate limiter.
func (*RateLimiter) Allow ¶
func (rl *RateLimiter) Allow(clientIP string) bool
Allow checks if a request from the given IP is allowed. Returns true if allowed, false if rate limited.
type RequestDeduplicator ¶
type RequestDeduplicator struct {
// contains filtered or unexported fields
}
RequestDeduplicator prevents duplicate requests from flooding the upstream. Uses a hash of the request body to detect duplicates within a time window.
func NewRequestDeduplicator ¶
func NewRequestDeduplicator(window time.Duration) *RequestDeduplicator
NewRequestDeduplicator creates a new request deduplicator.
func (*RequestDeduplicator) Release ¶
func (d *RequestDeduplicator) Release(body json.RawMessage)
Release releases a deduplication slot.
func (*RequestDeduplicator) TryAcquire ¶
func (d *RequestDeduplicator) TryAcquire(body json.RawMessage) (context.Context, bool)
TryAcquire attempts to acquire a deduplication slot for a request. Returns a context to use for the request, and true if this is a new request. If false, the returned context is already cancelled and the caller should wait.
type RequestIDGenerator ¶
type RequestIDGenerator struct {
// contains filtered or unexported fields
}
RequestIDGenerator generates unique request IDs.
func NewRequestIDGenerator ¶
func NewRequestIDGenerator() *RequestIDGenerator
NewRequestIDGenerator creates a new request ID generator.
func (*RequestIDGenerator) Generate ¶
func (g *RequestIDGenerator) Generate() string
Generate creates a new unique request ID.