ip

package
v4.5.1 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2022 License: AGPL-3.0 Imports: 3 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// CFConnectingIP is an HeaderParser.
	// https://support.cloudflare.com/hc/en-us/articles/206776727-What-is-True-Client-IP-
	CFConnectingIP = HeaderParser{"CF-Connecting-IP", parseXForwardedForHeader}

	// TrueClientIP is an HeaderParser.
	TrueClientIP = HeaderParser{"True-Client-IP", parseXForwardedForHeader}

	// XForwardedFor is an HeaderParser.
	XForwardedFor = HeaderParser{"X-Forwarded-For", parseXForwardedForHeader}

	// Forwarded is an HeaderParser.
	Forwarded = HeaderParser{"Forwarded", parseForwardedHeader}

	// XRealIP is an HeaderParser.
	XRealIP = HeaderParser{"X-Real-IP", parseXRealIPHeader}

	// DefaultHeaderParser is a list of headers and corresponding parsers to look up the real client IP.
	// They will be check in order, the first non-empty one will be picked,
	// or else the remote address is selected.
	DefaultHeaderParser = []HeaderParser{
		CFConnectingIP,
		TrueClientIP,
		XForwardedFor,
		Forwarded,
		XRealIP,
	}
)

Functions

func Get

func Get(r *http.Request, parser []HeaderParser, allowed []net.IPNet) string

Get returns the IP from given request. It will try to extract the real client IP from headers if possible.

Types

type HeaderParser

type HeaderParser struct {
	Header string
	Parser ParseHeaderFunc
}

HeaderParser parses a header to extract the real client IP address.

type ParseHeaderFunc

type ParseHeaderFunc func(string) string

ParseHeaderFunc parses and validates an IP address from a header. It must return an empty string if the header or contained IP address is invalid.

Jump to

Keyboard shortcuts

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