Documentation
¶
Overview ¶
Package httpip resolves the real client IP of an HTTP request behind explicitly trusted proxies, and provides net/http middleware.
Forwarding headers are honored only when the direct peer (RemoteAddr) is a trusted proxy. X-Forwarded-For is walked right to left, skipping trusted hops; the first untrusted hop is the client. Never trust the leftmost X-Forwarded-For entry blindly — any client can set it.
Index ¶
- func FromContext(ctx context.Context) (netip.Addr, bool)
- func WithClientIP(ctx context.Context, a netip.Addr) context.Context
- type Resolver
- func (res *Resolver) ClientIP(r *http.Request) (netip.Addr, error)
- func (res *Resolver) Middleware(next http.Handler) http.Handler
- func (res *Resolver) Resolve(remoteAddr string, xff []string, xRealIP string) (netip.Addr, error)
- func (res *Resolver) Restrict(acl *ipx.ACL, next http.Handler) http.Handler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FromContext ¶
FromContext returns the client IP stored by Middleware.
Types ¶
type Resolver ¶
type Resolver struct {
// contains filtered or unexported fields
}
Resolver extracts client IPs. Immutable after New; safe for concurrent use.
func New ¶
New returns a Resolver trusting the given proxy networks. With none, forwarding headers are ignored and RemoteAddr is used.
func (*Resolver) Middleware ¶
Middleware stores the client IP in the request context. Requests whose IP cannot be resolved pass through without one.