identity

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package identity provides identity utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseTrustedProxies

func ParseTrustedProxies(values []string) ([]netip.Prefix, error)

ParseTrustedProxies parses CIDR strings into prefixes.

func RequestID

func RequestID(req *http.Request) string

RequestID extracts a request ID from standard headers.

Types

type ClientInfo

type ClientInfo struct {
	IP        netip.Addr
	IPString  string
	Scheme    string
	Host      string
	RequestID string
}

ClientInfo captures canonical client identity attributes.

type HeaderPolicy

type HeaderPolicy uint8

HeaderPolicy controls which forwarded headers may be honored.

const (
	// HeaderPolicyNone ignores forwarded headers.
	HeaderPolicyNone HeaderPolicy = 0
	// HeaderPolicyXForwarded trusts X-Forwarded-* headers from trusted proxies.
	HeaderPolicyXForwarded HeaderPolicy = 1 << iota
	// HeaderPolicyForwarded trusts RFC 7239 Forwarded headers from trusted proxies.
	HeaderPolicyForwarded
	// HeaderPolicyBoth trusts both Forwarded and X-Forwarded-* headers.
	HeaderPolicyBoth = HeaderPolicyXForwarded | HeaderPolicyForwarded
)

type Resolver

type Resolver struct {
	TrustedProxies []netip.Prefix
	HeaderPolicy   HeaderPolicy
}

Resolver derives canonical client identity values from an http.Request. Forwarded headers are honored only when the direct peer is trusted.

func (Resolver) ClientIP

func (r Resolver) ClientIP(req *http.Request) (netip.Addr, bool)

ClientIP returns the best-effort client IP address.

func (Resolver) ClientIPString

func (r Resolver) ClientIPString(req *http.Request) string

ClientIPString returns the best-effort client IP string.

func (Resolver) Host

func (r Resolver) Host(req *http.Request) string

Host returns the request host, honoring forwarded headers only for trusted proxies.

func (Resolver) Resolve

func (r Resolver) Resolve(req *http.Request) ClientInfo

Resolve extracts the canonical client identity from the request.

func (Resolver) Scheme

func (r Resolver) Scheme(req *http.Request) string

Scheme returns the request scheme, honoring forwarded headers only for trusted proxies.

func (Resolver) TrustsRemoteAddr

func (r Resolver) TrustsRemoteAddr(remote string) bool

TrustsRemoteAddr reports whether the remote address is within trusted proxies.

Jump to

Keyboard shortcuts

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