netproxy

package
v0.56.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package netproxy selects, per request, whether the global proxy configured under network.proxy receives the request or the request connects directly. The selector is pure: it never reads the environment, so a configured proxy replaces (rather than mixes with) HTTP_PROXY/HTTPS_PROXY/NO_PROXY.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseProxyURL

func ParseProxyURL(proxyURL string) (*url.URL, error)

ParseProxyURL validates network.proxy.url: an http://, https:// or socks5:// URL with a host. The value may carry credentials (keep them in ${VAR}); it is deliberately not part of the error text, which reaches logs and traces.

func ParseSites

func ParseSites(sites []string) ([]siteRule, error)

ParseSites validates every network.proxy.sites entry: "*", a host, a leading-dot suffix (".example.com" covers the domain and its subdomains) or a host:port. Paths and schemes are rejected, so a list can only name hosts.

Types

type ProxyFunc

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

ProxyFunc is the callback shape of http.Transport.Proxy.

type Selector

type Selector struct {
	// contains filtered or unexported fields
}

Selector routes requests whose target host is on the allowlist through one fixed proxy URL and lets every other request connect directly. It is immutable and safe for concurrent use; a nil Selector selects nothing.

func New

func New(proxyURL string, sites []string) (*Selector, error)

New validates a proxy URL and its site allowlist. The URL is required; sites may be empty, which opts no host in (an empty list never means "everything": write "*" for that).

func (*Selector) Match

func (s *Selector) Match(u *url.URL) bool

Match reports whether u is on the allowlist and therefore goes through the proxy. Only the URL's host and port are used; no DNS resolution is involved.

func (*Selector) ProxyFunc

func (s *Selector) ProxyFunc() ProxyFunc

ProxyFunc returns the http.Transport.Proxy function of the selector: the configured proxy for a matched request, nil (direct) for every other one. A nil selector returns a nil function, so callers keep their previous transport.

func (*Selector) URL

func (s *Selector) URL() *url.URL

URL returns the proxy URL, e.g. for the dial check of a fetch target; nil for a nil selector.

Jump to

Keyboard shortcuts

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