Imports #
"errors"
"fmt"
"net"
"net/netip"
"net/url"
"os"
"strings"
"unicode/utf8"
"golang.org/x/net/idna"
"errors"
"fmt"
"net"
"net/netip"
"net/url"
"os"
"strings"
"unicode/utf8"
"golang.org/x/net/idna"
var portMap = map[string]string{...}
matcher represents the matching rule for a given value in the NO_PROXY list
type matcher interface {
match(host string, port string, ip net.IP) bool
}
Config holds configuration for HTTP proxy settings. See FromEnvironment for details.
type Config struct {
HTTPProxy string
HTTPSProxy string
NoProxy string
CGI bool
}
allMatch matches on all possible inputs
type allMatch struct {
}
type cidrMatch struct {
cidr *net.IPNet
}
config holds the parsed configuration for HTTP proxy settings.
type config struct {
Config
httpsProxy *url.URL
httpProxy *url.URL
ipMatchers []matcher
domainMatchers []matcher
}
type domainMatch struct {
host string
port string
matchHost bool
}
type ipMatch struct {
ip net.IP
port string
}
FromEnvironment returns a Config instance populated from the environment variables HTTP_PROXY, HTTPS_PROXY and NO_PROXY (or the lowercase versions thereof). The environment values may be either a complete URL or a "host[:port]", in which case the "http" scheme is assumed. An error is returned if the value is a different form.
func FromEnvironment() *Config
ProxyFunc returns a function that determines the proxy URL to use for a given request URL. Changing the contents of cfg will not affect proxy functions created earlier. A nil URL and nil error are returned if no proxy is defined in the environment, or a proxy should not be used for the given request, as defined by NO_PROXY. As a special case, if req.URL.Host is "localhost" or a loopback address (with or without a port number), then a nil URL and nil error will be returned.
func (cfg *Config) ProxyFunc() (func(reqURL *url.URL) (*url.URL, error))
canonicalAddr returns url.Host but always with a ":port" suffix
func canonicalAddr(url *url.URL) string
func getEnvAny(names ...string) string
Given a string of the form "host", "host:port", or "[ipv6::address]:port", return true if the string includes a port.
func hasPort(s string) bool
func idnaASCII(v string) (string, error)
func (c *config) init()
func isASCII(s string) bool
func (a allMatch) match(host string, port string, ip net.IP) bool
func (m cidrMatch) match(host string, port string, ip net.IP) bool
func (m ipMatch) match(host string, port string, ip net.IP) bool
func (m domainMatch) match(host string, port string, ip net.IP) bool
func parseProxy(proxy string) (*url.URL, error)
func (cfg *config) proxyForURL(reqURL *url.URL) (*url.URL, error)
useProxy reports whether requests to addr should use a proxy, according to the NO_PROXY or no_proxy environment variable. addr is always a canonicalAddr with a host and port.
func (cfg *config) useProxy(addr string) bool
Generated with Arrow