proxy

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const MaxForwardedForHops = 32

MaxForwardedForHops limits the amount of X-Forwarded-For entries inspected per request. The trusted chain is walked from the right, closest to the app.

Variables

This section is empty.

Functions

func ParsePrefixes

func ParsePrefixes(cidrs []string) ([]netip.Prefix, error)

ParsePrefixes parses trusted proxy CIDR strings once at application startup.

func RealIP

func RealIP(r *http.Request, trustedProxies []netip.Prefix) string

RealIP reports the original client IP when the immediate peer is trusted. The RFC 7239 Forwarded header (for= parameters) takes precedence over the legacy X-Forwarded-For and X-Real-IP headers; all chain sources are walked with the same right-to-left trusted-hop semantics.

func RemoteAddrIP

func RemoteAddrIP(remoteAddr string) (addr netip.Addr, fallback string, ok bool)

RemoteAddrIP parses an http.Request RemoteAddr and returns an IP-only string for valid addresses. If RemoteAddr is unparseable, fallback is the trimmed RemoteAddr value and ok is false.

func Scheme

func Scheme(r *http.Request, trustedProxies []netip.Prefix) string

Scheme reports the original client scheme when the immediate peer is trusted. The RFC 7239 Forwarded header takes precedence over the legacy X-Forwarded-* headers.

func Trusted

func Trusted(prefixes []netip.Prefix, addr netip.Addr) bool

Trusted reports whether addr is contained in any trusted proxy prefix.

Types

This section is empty.

Jump to

Keyboard shortcuts

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