hostmatcher

package
v1.27.0 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const MatchBuiltinExternal = "external"

MatchBuiltinExternal A valid global-unicast IP that is neither private (see MatchBuiltinPrivate) nor a reserved special-purpose range (see reservedIPNets); i.e. a routable host on the public internet.

View Source
const MatchBuiltinLoopback = "loopback"

MatchBuiltinLoopback 127.0.0.0/8 for IPv4 and ::1/128 for IPv6, localhost is included.

View Source
const MatchBuiltinPrivate = "private"

MatchBuiltinPrivate RFC 1918 (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16) and RFC 4193 (FC00::/7), plus the reserved special-purpose ranges in reservedIPNets (CGNAT, NAT64, cloud metadata, etc.). Also called LAN/Intranet.

Variables

This section is empty.

Functions

func NewDialContext

func NewDialContext(usage string, allowList, blockList *HostMatchList, proxy *url.URL) func(ctx context.Context, network, addr string) (net.Conn, error)

NewDialContext returns a DialContext for Transport, the DialContext will do allow/block list check

func NewHTTPTransport

func NewHTTPTransport(usage string, allowList, blockList *HostMatchList, proxyFunc func(*http.Request) (*url.URL, error), proxyURLFixed *url.URL, tlsConfig *tls.Config) *http.Transport

NewHTTPTransport builds an http.Transport that validates the request target against the allow/block lists on the direct-dial path (DialContext). When an HTTP proxy is configured the proxy resolves and dials the target itself, so restricting the proxied target is the proxy server's responsibility, not Gitea's. proxyFunc selects the proxy URL per request (the http.Transport.Proxy selector, e.g. proxy.Proxy()); proxyURLFixed is the fixed proxy address the dialer must always permit; tlsConfig may be nil. blockList may be nil for callers that only maintain an allow-list.

Types

type HostMatchList

type HostMatchList struct {
	SettingKeyHint string
	SettingValue   string
	// contains filtered or unexported fields
}

HostMatchList is used to check if a host or IP is in a list.

func ParseHostMatchList

func ParseHostMatchList(settingKeyHint, hostList string) *HostMatchList

ParseHostMatchList parses the host list HostMatchList

func ParseSimpleMatchList

func ParseSimpleMatchList(settingKeyHint, matchList string) *HostMatchList

ParseSimpleMatchList parse a simple matchlist (no built-in networks, no CIDR support, only wildcard pattern match)

func (*HostMatchList) AppendBuiltin

func (hl *HostMatchList) AppendBuiltin(builtin string)

AppendBuiltin appends more builtins to match

func (*HostMatchList) IsEmpty

func (hl *HostMatchList) IsEmpty() bool

IsEmpty checks if the checklist is empty

func (*HostMatchList) MatchHostName

func (hl *HostMatchList) MatchHostName(host string) bool

MatchHostName checks if the host matches an allow/deny(block) list

func (*HostMatchList) MatchHostOrIP

func (hl *HostMatchList) MatchHostOrIP(host string, ip net.IP) bool

MatchHostOrIP checks if the host or IP matches an allow/deny(block) list

func (*HostMatchList) MatchIPAddr

func (hl *HostMatchList) MatchIPAddr(ip net.IP) bool

MatchIPAddr checks if the IP matches an allow/deny(block) list, it's safe to pass `nil` to `ip`

Jump to

Keyboard shortcuts

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