Documentation
¶
Overview ¶
Package proxyenv resolves which proxy, if any, a target-facing request goes through, and says where that choice came from.
The rules:
- --proxy (the CLI value) proxies every request, whatever its scheme and host. NO_PROXY does not apply to it: an operator who typed a proxy wants to see everything in it.
- Otherwise the environment decides, by the request's scheme: HTTPS_PROXY (https_proxy) for https, HTTP_PROXY (http_proxy) for http, ALL_PROXY (all_proxy) for either when the scheme's own variable is unset.
- NO_PROXY (no_proxy) exempts hosts from an environment proxy: "*", a host or domain suffix ("example.com" and ".example.com" both match sub.example.com), an IP, a CIDR, each optionally with ":port".
- Loopback is NOT exempt by itself. Go's net/http/httpproxy always bypasses localhost, which hides a local target from the operator's proxy; here a loopback target is proxied unless NO_PROXY names it.
Uppercase variables win over lowercase ones. The resolved Choice carries the variable each proxy came from, so plans, banners and errors can name it.
Index ¶
- type Choice
- func (c Choice) Any() bool
- func (c Choice) Bypass(scheme, host string) bool
- func (c Choice) Describe(target string) string
- func (c Choice) Err() error
- func (c Choice) For(u *url.URL) *Route
- func (c Choice) ForHost(scheme, host string) *Route
- func (c Choice) Func() func(*http.Request) (*url.URL, error)
- func (c Choice) NoProxy() (value, source string)
- func (c Choice) Proxies() []*Route
- func (c Choice) Routes() []RouteView
- func (c Choice) Summary() string
- type Route
- type RouteView
- type Source
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Choice ¶
type Choice struct {
// contains filtered or unexported fields
}
Choice is the resolved proxy configuration.
func FromEnvironment ¶
FromEnvironment is Resolve(cliProxy, os.Getenv).
func Resolve ¶
Resolve builds the Choice for cliProxy (the --proxy value, "" for none) and the environment read through getenv (os.Getenv when nil).
func (Choice) Bypass ¶
Bypass reports whether NO_PROXY exempts host (host or host:port) from an environment proxy. --proxy is never bypassed.
func (Choice) Describe ¶
Describe renders the route a request to target takes, for a banner or an error: "http://127.0.0.1:8080 (from HTTPS_PROXY)", "direct (NO_PROXY)", or "" when no proxy is configured at all.
func (Choice) ForHost ¶
ForHost returns the route for a request with this scheme to host (host or host:port), or nil to connect directly.
func (Choice) Func ¶
Func is the http.Transport Proxy func for this choice, or nil when nothing is ever proxied (so the transport connects directly).
func (Choice) NoProxy ¶
NoProxy returns the NO_PROXY value in effect and the variable it came from ("", "" when none, or when --proxy makes it irrelevant).
func (Choice) Routes ¶
Routes lists the configured routes for display: one per scheme the environment set, or the single --proxy route as scheme "*".
func (Choice) Summary ¶
Summary renders every route on one line for a banner: "http://h:8080 for https (HTTPS_PROXY); NO_PROXY=localhost". "" when nothing is proxied.
type Route ¶
type Route struct {
URL *url.URL
Source Source
// Everything marks --proxy (or VIGOLIUM_PROXY): every request goes
// through it and NO_PROXY does not apply.
Everything bool
}
Route is one proxy and where it came from.
type RouteView ¶
type RouteView struct {
// Scheme is the request scheme the route applies to, "*" for every scheme.
Scheme string `json:"scheme"`
URL string `json:"url"`
Source string `json:"source"`
}
RouteView is a route as plans and documents show it.
type Source ¶
type Source = string
Source names where a proxy came from: SourceFlag, or the environment variable it was read from.
const SourceFlag Source = "--proxy"
SourceFlag is a proxy given with --proxy.
const SourceVigoliumProxy Source = "VIGOLIUM_PROXY"
SourceVigoliumProxy is the environment fallback for --proxy; it proxies every request like the flag does.