httpproxy

Imports

Imports #

"errors"
"fmt"
"net"
"net/netip"
"net/url"
"os"
"strings"
"unicode/utf8"
"golang.org/x/net/idna"

Constants & Variables

portMap var #

var portMap = map[string]string{...}

Interfaces

matcher interface #

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
}

Structs

Config struct #

Config holds configuration for HTTP proxy settings. See FromEnvironment for details.

type Config struct {
HTTPProxy string
HTTPSProxy string
NoProxy string
CGI bool
}

allMatch struct #

allMatch matches on all possible inputs

type allMatch struct {

}

cidrMatch struct #

type cidrMatch struct {
cidr *net.IPNet
}

config struct #

config holds the parsed configuration for HTTP proxy settings.

type config struct {
Config
httpsProxy *url.URL
httpProxy *url.URL
ipMatchers []matcher
domainMatchers []matcher
}

domainMatch struct #

type domainMatch struct {
host string
port string
matchHost bool
}

ipMatch struct #

type ipMatch struct {
ip net.IP
port string
}

Functions

FromEnvironment function #

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 method #

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 function #

canonicalAddr returns url.Host but always with a ":port" suffix

func canonicalAddr(url *url.URL) string

getEnvAny function #

func getEnvAny(names ...string) string

hasPort function #

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

idnaASCII function #

func idnaASCII(v string) (string, error)

init method #

func (c *config) init()

isASCII function #

func isASCII(s string) bool

match method #

func (a allMatch) match(host string, port string, ip net.IP) bool

match method #

func (m cidrMatch) match(host string, port string, ip net.IP) bool

match method #

func (m ipMatch) match(host string, port string, ip net.IP) bool

match method #

func (m domainMatch) match(host string, port string, ip net.IP) bool

parseProxy function #

func parseProxy(proxy string) (*url.URL, error)

proxyForURL method #

func (cfg *config) proxyForURL(reqURL *url.URL) (*url.URL, error)

useProxy method #

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