proxyenv

package
v0.5.7 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 6 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

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

func FromEnvironment(cliProxy string) Choice

FromEnvironment is Resolve(cliProxy, os.Getenv).

func Resolve

func Resolve(cliProxy string, getenv func(string) string) Choice

Resolve builds the Choice for cliProxy (the --proxy value, "" for none) and the environment read through getenv (os.Getenv when nil).

func (Choice) Any

func (c Choice) Any() bool

Any reports whether any request could be proxied.

func (Choice) Bypass

func (c Choice) Bypass(scheme, host string) bool

Bypass reports whether NO_PROXY exempts host (host or host:port) from an environment proxy. --proxy is never bypassed.

func (Choice) Describe

func (c Choice) Describe(target string) string

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) Err

func (c Choice) Err() error

Err is the first proxy value that could not be parsed, or nil.

func (Choice) For

func (c Choice) For(u *url.URL) *Route

For returns the route a request to u takes, or nil to connect directly.

func (Choice) ForHost

func (c Choice) ForHost(scheme, host string) *Route

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 (c Choice) Func() func(*http.Request) (*url.URL, error)

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

func (c Choice) NoProxy() (value, source string)

NoProxy returns the NO_PROXY value in effect and the variable it came from ("", "" when none, or when --proxy makes it irrelevant).

func (Choice) Proxies

func (c Choice) Proxies() []*Route

Proxies returns every distinct proxy a request could be sent through.

func (Choice) Routes

func (c Choice) Routes() []RouteView

Routes lists the configured routes for display: one per scheme the environment set, or the single --proxy route as scheme "*".

func (Choice) Summary

func (c Choice) Summary() string

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.

func (*Route) Redacted

func (r *Route) Redacted() string

Redacted is the proxy URL with any password masked, for display.

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.

Jump to

Keyboard shortcuts

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