request

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: May 12, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// HeaderCloudflareConnectingIP is set by Cloudflare to the connecting client IP.
	HeaderCloudflareConnectingIP = "CF-Connecting-IP"
	// HeaderXForwardedFor is the standard proxy header for client IP chain.
	HeaderXForwardedFor = "X-Forwarded-For"
	// EnvTrustCloudflareHeaders controls global default for trusting CF-Connecting-IP.
	EnvTrustCloudflareHeaders = "GATEON_TRUST_CLOUDFLARE_HEADERS"
	// EnvTrustedProxies is a comma-separated list of CIDRs that are trusted to provide X-Forwarded-For or CF-Connecting-IP.
	EnvTrustedProxies = "GATEON_TRUSTED_PROXIES"
)

Variables

This section is empty.

Functions

func GenerateID added in v0.1.2

func GenerateID() string

GenerateID creates a new unique request ID.

func GetClientIP

func GetClientIP(r *http.Request, trustCloudflare bool) string

GetClientIP returns the client IP from the request, using CF-Connecting-IP when trustCloudflare is true (e.g. when Gateon is behind Cloudflare), otherwise X-Forwarded-For (leftmost), falling back to RemoteAddr.

func GetCountry added in v0.6.0

func GetCountry(r *http.Request) string

GetCountry returns the client country from the request context, or from CF-IPCountry header if present (and trusted), or "XX" (Unknown).

func GetID added in v0.1.2

func GetID(r *http.Request) string

GetID returns the request ID from the request context or "unknown".

func ParseTrustCloudflare

func ParseTrustCloudflare(val string) bool

ParseTrustCloudflare parses a config value for trust_cloudflare_headers. If empty, falls back to TrustCloudflareFromEnv().

func ParseTrustCloudflareStrict

func ParseTrustCloudflareStrict(val string) bool

ParseTrustCloudflareStrict parses trust_cloudflare_headers without env fallback. Returns false when empty or invalid.

func RegisterCountryResolver added in v0.6.9

func RegisterCountryResolver(r CountryResolver)

RegisterCountryResolver registers a global resolver for IP to Country mapping.

func TrustCloudflareFromEnv

func TrustCloudflareFromEnv() bool

TrustCloudflareFromEnv returns true if GATEON_TRUST_CLOUDFLARE_HEADERS is set to a truthy value (true, 1, yes). Used as default when middleware config omits trust_cloudflare_headers.

func WithCountry added in v0.6.0

func WithCountry(ctx context.Context, country string) context.Context

WithCountry adds a client country to the context.

func WithID added in v0.1.2

func WithID(ctx context.Context, id string) context.Context

WithID adds a request ID to the context.

Types

type CountryResolver added in v0.6.9

type CountryResolver interface {
	Resolve(ip string) string
}

CountryResolver is an interface for resolving IPs to country codes.

Jump to

Keyboard shortcuts

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