Involved Source Files Package httpproxy provides support for HTTP proxy determination
based on environment variables, as provided by net/http's
ProxyFromEnvironment function.
The API is not subject to the Go 1 compatibility promise and may change at
any time.
Package-Level Type Names (total 7, in which 1 is exported)
/* sort exporteds by: | */
Config holds configuration for HTTP proxy settings. See
FromEnvironment for details. CGI holds whether the current process is running
as a CGI handler (FromEnvironment infers this from the
presence of a REQUEST_METHOD environment variable).
When this is set, ProxyForURL will return an error
when HTTPProxy applies, because a client could be
setting HTTP_PROXY maliciously. See https://golang.org/s/cgihttpproxy. HTTPProxy represents the value of the HTTP_PROXY or
http_proxy environment variable. It will be used as the proxy
URL for HTTP requests unless overridden by NoProxy. HTTPSProxy represents the HTTPS_PROXY or https_proxy
environment variable. It will be used as the proxy URL for
HTTPS requests unless overridden by NoProxy. NoProxy represents the NO_PROXY or no_proxy environment
variable. It specifies a string that contains comma-separated values
specifying hosts that should be excluded from proxying. Each value is
represented by an IP address prefix (1.2.3.4), an IP address prefix in
CIDR notation (1.2.3.4/8), a domain name, or a special DNS label (*).
An IP address prefix and domain name can also include a literal port
number (1.2.3.4:80).
A domain name matches that name and all subdomains. A domain name with
a leading "." matches subdomains only. For example "foo.com" matches
"foo.com" and "bar.foo.com"; ".y.com" matches "x.y.com" but not "y.com".
A single asterisk (*) indicates that no proxying should be done.
A best effort is made to parse the string and errors are
ignored. 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 FromEnvironment() *Config
allMatch matches on all possible inputs( allMatch) match(host, port string, ip net.IP) bool
allMatch : matcher
config holds the parsed configuration for HTTP proxy settings. Config represents the original configuration as defined above. CGI holds whether the current process is running
as a CGI handler (FromEnvironment infers this from the
presence of a REQUEST_METHOD environment variable).
When this is set, ProxyForURL will return an error
when HTTPProxy applies, because a client could be
setting HTTP_PROXY maliciously. See https://golang.org/s/cgihttpproxy. HTTPProxy represents the value of the HTTP_PROXY or
http_proxy environment variable. It will be used as the proxy
URL for HTTP requests unless overridden by NoProxy. HTTPSProxy represents the HTTPS_PROXY or https_proxy
environment variable. It will be used as the proxy URL for
HTTPS requests unless overridden by NoProxy. NoProxy represents the NO_PROXY or no_proxy environment
variable. It specifies a string that contains comma-separated values
specifying hosts that should be excluded from proxying. Each value is
represented by an IP address prefix (1.2.3.4), an IP address prefix in
CIDR notation (1.2.3.4/8), a domain name, or a special DNS label (*).
An IP address prefix and domain name can also include a literal port
number (1.2.3.4:80).
A domain name matches that name and all subdomains. A domain name with
a leading "." matches subdomains only. For example "foo.com" matches
"foo.com" and "bar.foo.com"; ".y.com" matches "x.y.com" but not "y.com".
A single asterisk (*) indicates that no proxying should be done.
A best effort is made to parse the string and errors are
ignored. domainMatchers represent all values in the NoProxy that are a domain
name or hostname & domain name httpProxy is the parsed URL of the HTTPProxy if defined. httpsProxy is the parsed URL of the HTTPSProxy if defined. ipMatchers represent all values in the NoProxy that are IP address
prefixes or an IP address in CIDR notation. 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.(*config) init()(*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.
matcher represents the matching rule for a given value in the NO_PROXY list match returns true if the host and optional port or ip and optional port
are allowedallMatchcidrMatchdomainMatchipMatch
Package-Level Functions (total 7, in which 1 is exported)
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.
canonicalAddr returns url.Host but always with a ":port" suffix
The pages are generated with Goldsv0.6.7. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds.