Documentation ¶
Overview ¶
Package clientip provides(in a best effort manner) a client's IP address.
Index ¶
- func DirectAddress(remoteAddr string) string
- func Get(r *http.Request) string
- func Leftmost(headers http.Header) string
- func ProxyHeader(headers http.Header) string
- func Rightmost(headers http.Header) string
- func SingleIPHeader(headerName string, headers http.Header) string
- func With(r *http.Request, clientAddr string) *http.Request
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DirectAddress ¶
DirectAddress returns the client socket IP, stripped of port. This strategy should be used if the server accepts direct connections, rather than through a proxy.
func Get ¶
Get returns the "real" client IP address. See github.com/komuw/ong/middleware.ClientIP
func Leftmost ¶
Leftmost derives the client IP from the leftmost valid and non-private IP address in the X-Fowarded-For or Forwarded header. This strategy should be used when a valid, non-private IP closest to the client is desired. Note: This MUST NOT be used for security purposes. This IP can be trivially SPOOFED.
The returned IP may contain a zone identifier. If no valid IP can be derived, empty string will be returned.
func ProxyHeader ¶ added in v0.0.47
ProxyHeader derives an IP address based off the PROXY protocol v1.
func Rightmost ¶
Rightmost derives the client IP from the rightmost valid and non-private IP address in the X-Fowarded-For or Forwarded header. This strategy should be used when all reverse proxies between the internet and the server have private-space IP addresses.
The returned IP may contain a zone identifier. If no valid IP can be derived, empty string will be returned.
func SingleIPHeader ¶
SingleIPHeader derives an IP address from a single-IP header. A non-exhaustive list of such single-IP headers is: X-Real-IP, CF-Connecting-IP, True-Client-IP, Fastly-Client-IP, X-Azure-ClientIP, X-Azure-SocketIP, Fly-Client-IP. This strategy should be used when the given header is added by a trusted reverse proxy. You MUST ensure that this header is not spoofable (as is possible with Akamai's use of True-Client-IP, Fastly's default use of Fastly-Client-IP, and Azure's X-Azure-ClientIP). See the single-IP wiki page for more info.
The returned IP may contain a zone identifier. If no valid IP can be derived, empty string will be returned.
Types ¶
This section is empty.