Documentation
¶
Overview ¶
Package clientip extracts the client's real IP from a request.
X-Forwarded-For is trusted only when it comes from a configured proxy, and the first untrusted address is taken scanning from right to left: the rightmost entry was added by the proxy nearest to us, while the leftmost can be anything the client chooses to write (for example private addresses added by a corporate network proxy). This matches Caddy's trusted_proxies_strict.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Proxied ¶
Proxied reports whether the request came through a proxy: it carries any X-Forwarded-* header or one of the headers above, or it is HTTP/1.0 (nginx's default proxy_pass uses HTTP/1.0 for upstream fetches and does not add X-Forwarded-For). The client may also write these headers itself, so they are only ever used to refuse, never to allow.
Types ¶
type Resolver ¶
type Resolver struct {
// contains filtered or unexported fields
}
Resolver resolves client IP addresses and supports atomic updates to its trusted proxy prefixes.
func New ¶
New creates a Resolver. When trusted is empty no proxy is trusted and the TCP source address is used directly.
func (*Resolver) Forwarded ¶
Forwarded returns the client address passed on by a trusted proxy: the TCP peer is a trusted proxy and the address was actually taken from X-Real-IP (with use_x_real_ip) or X-Forwarded-For. Otherwise ok is false.
func (*Resolver) SetTrusted ¶
SetTrusted atomically replaces the trusted proxy ranges.