Documentation
¶
Overview ¶
Package clientip answers "where did this request come from".
It is one short function, in a package of its own, because getting it wrong is silent. A server that believes X-Forwarded-For unconditionally lets any caller name their own address, and every limit keyed on one becomes decorative — the requests still arrive, the counter still counts, and it counts a different fictional client each time. A server that never believes it sees only the load balancer, so one address carries everybody and the limit is either off or on for the whole internet.
The answer is neither: believe the header exactly when the immediate peer is a proxy the application named. That has to be the same answer everywhere it is asked, which is why this is not a method on whichever handler needed it first.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Of ¶
Of returns the address the request came from.
trusted are the networks whose X-Forwarded-For may be believed. Empty trusts none of them, which is the right default and the wrong setting behind a load balancer — see Parse for the one that is not a choice.
The zero netip.Addr is a peer that could not be parsed at all, which happens on a Unix socket and in tests. Callers should treat it as "no address" rather than as one, since every request with no address would otherwise share a budget.
Types ¶
This section is empty.