nethttp

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 31, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package nethttp provides rate limiting middleware for Go's standard net/http package. It features IP spoofing protection with trusted proxy CIDR filtering and custom key extraction.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractClientIP added in v1.1.0

func ExtractClientIP(r *http.Request, trustedProxies []string) string

ExtractClientIP securely extracts the client's real IP address from an http.Request. Header values (X-Forwarded-For, X-Real-IP) are parsed only if RemoteAddr originates from a trusted proxy.

func New

func New(limiter *distlimit.Limiter, opts ...Option) func(http.Handler) http.Handler

New returns a standard net/http middleware adapter function `func(http.Handler) http.Handler` configured with the specified distlimit.Limiter and options.

Types

type Config added in v1.1.0

type Config struct {
	// contains filtered or unexported fields
}

Config holds configuration parameters for the net/http rate limit middleware.

type Option

type Option func(*Config)

Option configures functional parameters for the net/http rate limit middleware.

func WithKeyFunc added in v1.1.0

func WithKeyFunc(fn distlimit.KeyFunc) Option

WithKeyFunc configures a custom key extraction function from the request context.

func WithRouteLabeling added in v1.2.0

func WithRouteLabeling(enable bool) Option

WithRouteLabeling enables passing the HTTP request URL path/pattern as the route label in telemetry events.

func WithTrustedProxies added in v1.1.0

func WithTrustedProxies(proxies []string) Option

WithTrustedProxies configures a list of trusted proxy IPs or CIDR networks for safely parsing X-Forwarded-For headers.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL