netclient

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package netclient builds HTTP clients and proxy resolvers that share fairpeer's user-facing proxy settings. web_fetch reuses the resolver while keeping its own dial-time SSRF guard.

Index

Constants

View Source
const (
	ModeAuto   = "auto"
	ModeEnv    = "env"
	ModeCustom = "custom"
	ModeOff    = "off"
)

Variables

View Source
var CGNATRange = mustCIDR("100.64.0.0/10")

CGNATRange is RFC 6598 shared address space (100.64.0.0/10). Go's IsPrivate doesn't cover it, yet some clouds host instance metadata there (Alibaba Cloud at 100.100.100.200), so it's an SSRF target.

Functions

func BlockedFetchIP

func BlockedFetchIP(ip net.IP) bool

BlockedFetchIP reports whether ip is an address that outbound fetches must not reach. Covers RFC1918, link-local, unspecified, and CGNAT ranges.

func NewHTTPClient

func NewHTTPClient(spec ProxySpec, opts TransportOptions) (*http.Client, error)

NewHTTPClient returns an HTTP client with fairpeer proxy settings applied.

func NewTransport

func NewTransport(spec ProxySpec, opts TransportOptions) (*http.Transport, error)

NewTransport clones net/http's default transport and overlays the requested proxy and timeout knobs. Cloning preserves defaults such as HTTP/2 support, connection pooling, and environment-proxy behavior for auto/env modes.

func NormalizeMode

func NormalizeMode(mode string) string

NormalizeMode maps empty and unknown modes to auto, preserving a fail-open default for older configs.

func ProxyFunc

func ProxyFunc(spec ProxySpec) (func(*http.Request) (*url.URL, error), error)

ProxyFunc returns the per-request proxy resolver for spec.

func ProxyURLFor

func ProxyURLFor(spec ProxySpec, req *http.Request) (string, error)

ProxyURLFor resolves the proxy URL string for a given request under spec. Returns "" when no proxy applies. This is a convenience wrapper around ProxyFunc for callers that only need the URL string.

func Summary

func Summary(spec ProxySpec) string

Summary returns a redacted, user-facing description for diagnostics.

func Validate

func Validate(spec ProxySpec) error

Validate reports whether spec can be used. Non-custom modes have no required fields; custom needs either a complete URL or a structured server+port.

Types

type ProxySpec

type ProxySpec struct {
	Mode        string
	URL         string
	NoProxy     string
	Type        string
	Server      string
	Port        int
	Username    string
	Password    string
	DirectHosts []string
}

ProxySpec is the resolved proxy configuration used by network clients. URL is an advanced override; otherwise Type/Server/Port/Credentials are composed into a proxy URL. NoProxy is honored for custom proxies. DirectHosts always bypass the proxy in every mode (the caller derives them, e.g. from no_proxy providers).

type TransportOptions

type TransportOptions struct {
	DialTimeout           time.Duration
	KeepAlive             time.Duration
	TLSHandshakeTimeout   time.Duration
	ResponseHeaderTimeout time.Duration
}

TransportOptions lets callers keep their existing network timeouts while sharing proxy behavior.

Jump to

Keyboard shortcuts

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