// Code generated by golang.org/x/tools/cmd/bundle. DO NOT EDIT.//go:generate bundle -o x_net_proxy.go golang.org/x/net/proxy// Package proxy provides support for a variety of protocols to proxy network// data.//package websocketimport ()type proxy_direct struct{}// Direct is a direct proxy: one that makes network connections directly.var proxy_Direct = proxy_direct{}func (proxy_direct) (, string) (net.Conn, error) {returnnet.Dial(, )}// A PerHost directs connections to a default Dialer unless the host name// requested matches one of a number of exceptions.type proxy_PerHost struct { def, bypass proxy_Dialer bypassNetworks []*net.IPNet bypassIPs []net.IP bypassZones []string bypassHosts []string}// NewPerHost returns a PerHost Dialer that directs connections to either// defaultDialer or bypass, depending on whether the connection matches one of// the configured rules.func proxy_NewPerHost(, proxy_Dialer) *proxy_PerHost {return &proxy_PerHost{def: ,bypass: , }}// Dial connects to the address addr on the given network through either// defaultDialer or bypass.func ( *proxy_PerHost) (, string) ( net.Conn, error) { , , := net.SplitHostPort()if != nil {returnnil, }return .dialerForRequest().Dial(, )}func ( *proxy_PerHost) ( string) proxy_Dialer {if := net.ParseIP(); != nil {for , := range .bypassNetworks {if .Contains() {return .bypass } }for , := range .bypassIPs {if .Equal() {return .bypass } }return .def }for , := range .bypassZones {ifstrings.HasSuffix(, ) {return .bypass }if == [1:] {// For a zone ".example.com", we match "example.com" // too.return .bypass } }for , := range .bypassHosts {if == {return .bypass } }return .def}// AddFromString parses a string that contains comma-separated values// specifying hosts that should use the bypass proxy. Each value is either an// IP address, a CIDR range, a zone (*.example.com) or a host name// (localhost). A best effort is made to parse the string and errors are// ignored.func ( *proxy_PerHost) ( string) { := strings.Split(, ",")for , := range { = strings.TrimSpace()iflen() == 0 {continue }ifstrings.Contains(, "/") {// We assume that it's a CIDR address like 127.0.0.0/8if , , := net.ParseCIDR(); == nil { .AddNetwork() }continue }if := net.ParseIP(); != nil { .AddIP()continue }ifstrings.HasPrefix(, "*.") { .AddZone([1:])continue } .AddHost() }}// AddIP specifies an IP address that will use the bypass proxy. Note that// this will only take effect if a literal IP address is dialed. A connection// to a named host will never match an IP.func ( *proxy_PerHost) ( net.IP) { .bypassIPs = append(.bypassIPs, )}// AddNetwork specifies an IP range that will use the bypass proxy. Note that// this will only take effect if a literal IP address is dialed. A connection// to a named host will never match.func ( *proxy_PerHost) ( *net.IPNet) { .bypassNetworks = append(.bypassNetworks, )}// AddZone specifies a DNS suffix that will use the bypass proxy. A zone of// "example.com" matches "example.com" and all of its subdomains.func ( *proxy_PerHost) ( string) {ifstrings.HasSuffix(, ".") { = [:len()-1] }if !strings.HasPrefix(, ".") { = "." + } .bypassZones = append(.bypassZones, )}// AddHost specifies a host name that will use the bypass proxy.func ( *proxy_PerHost) ( string) {ifstrings.HasSuffix(, ".") { = [:len()-1] } .bypassHosts = append(.bypassHosts, )}// A Dialer is a means to establish a connection.type proxy_Dialer interface {// Dial connects to the given address via the proxy. Dial(network, addr string) (c net.Conn, err error)}// Auth contains authentication parameters that specific Dialers may require.type proxy_Auth struct { User, Password string}// FromEnvironment returns the dialer specified by the proxy related variables in// the environment.func proxy_FromEnvironment() proxy_Dialer { := proxy_allProxyEnv.Get()iflen() == 0 {returnproxy_Direct } , := url.Parse()if != nil {returnproxy_Direct } , := proxy_FromURL(, proxy_Direct)if != nil {returnproxy_Direct } := proxy_noProxyEnv.Get()iflen() == 0 {return } := proxy_NewPerHost(, proxy_Direct) .AddFromString()return}// proxySchemes is a map from URL schemes to a function that creates a Dialer// from a URL with such a scheme.var proxy_proxySchemes map[string]func(*url.URL, proxy_Dialer) (proxy_Dialer, error)// RegisterDialerType takes a URL scheme and a function to generate Dialers from// a URL with that scheme and a forwarding Dialer. Registered schemes are used// by FromURL.func proxy_RegisterDialerType( string, func(*url.URL, proxy_Dialer) (proxy_Dialer, error)) {ifproxy_proxySchemes == nil {proxy_proxySchemes = make(map[string]func(*url.URL, proxy_Dialer) (proxy_Dialer, error)) }proxy_proxySchemes[] = }// FromURL returns a Dialer given a URL specification and an underlying// Dialer for it to make network requests.func proxy_FromURL( *url.URL, proxy_Dialer) (proxy_Dialer, error) {var *proxy_Authif .User != nil { = new(proxy_Auth) .User = .User.Username()if , := .User.Password(); { .Password = } }switch .Scheme {case"socks5":returnproxy_SOCKS5("tcp", .Host, , ) }// If the scheme doesn't match any of the built-in schemes, see if it // was registered by another package.ifproxy_proxySchemes != nil {if , := proxy_proxySchemes[.Scheme]; {return (, ) } }returnnil, errors.New("proxy: unknown scheme: " + .Scheme)}var ( proxy_allProxyEnv = &proxy_envOnce{names: []string{"ALL_PROXY", "all_proxy"}, } proxy_noProxyEnv = &proxy_envOnce{names: []string{"NO_PROXY", "no_proxy"}, })// envOnce looks up an environment variable (optionally by multiple// names) once. It mitigates expensive lookups on some platforms// (e.g. Windows).// (Borrowed from net/http/transport.go)type proxy_envOnce struct { names []string once sync.Once val string}func ( *proxy_envOnce) () string { .once.Do(.init)return .val}func ( *proxy_envOnce) () {for , := range .names { .val = os.Getenv()if .val != "" {return } }}// SOCKS5 returns a Dialer that makes SOCKSv5 connections to the given address// with an optional username and password. See RFC 1928 and RFC 1929.func proxy_SOCKS5(, string, *proxy_Auth, proxy_Dialer) (proxy_Dialer, error) { := &proxy_socks5{network: ,addr: ,forward: , }if != nil { .user = .User .password = .Password }return , nil}type proxy_socks5 struct { user, password string network, addr string forward proxy_Dialer}const proxy_socks5Version = 5const ( proxy_socks5AuthNone = 0 proxy_socks5AuthPassword = 2)const proxy_socks5Connect = 1const ( proxy_socks5IP4 = 1 proxy_socks5Domain = 3 proxy_socks5IP6 = 4)var proxy_socks5Errors = []string{"","general failure","connection forbidden","network unreachable","host unreachable","connection refused","TTL expired","command not supported","address type not supported",}// Dial connects to the address addr on the given network via the SOCKS5 proxy.func ( *proxy_socks5) (, string) (net.Conn, error) {switch {case"tcp", "tcp6", "tcp4":default:returnnil, errors.New("proxy: no support for SOCKS5 proxy connections of type " + ) } , := .forward.Dial(.network, .addr)if != nil {returnnil, }if := .connect(, ); != nil { .Close()returnnil, }return , nil}// connect takes an existing connection to a socks5 proxy server,// and commands the server to extend that connection to target,// which must be a canonical address with a host and port.func ( *proxy_socks5) ( net.Conn, string) error { , , := net.SplitHostPort()if != nil {return } , := strconv.Atoi()if != nil {returnerrors.New("proxy: failed to parse port number: " + ) }if < 1 || > 0xffff {returnerrors.New("proxy: port number out of range: " + ) }// the size here is just an estimate := make([]byte, 0, 6+len()) = append(, proxy_socks5Version)iflen(.user) > 0 && len(.user) < 256 && len(.password) < 256 { = append(, 2/* num auth methods */, proxy_socks5AuthNone, proxy_socks5AuthPassword) } else { = append(, 1/* num auth methods */, proxy_socks5AuthNone) }if , := .Write(); != nil {returnerrors.New("proxy: failed to write greeting to SOCKS5 proxy at " + .addr + ": " + .Error()) }if , := io.ReadFull(, [:2]); != nil {returnerrors.New("proxy: failed to read greeting from SOCKS5 proxy at " + .addr + ": " + .Error()) }if [0] != 5 {returnerrors.New("proxy: SOCKS5 proxy at " + .addr + " has unexpected version " + strconv.Itoa(int([0]))) }if [1] == 0xff {returnerrors.New("proxy: SOCKS5 proxy at " + .addr + " requires authentication") }// See RFC 1929if [1] == proxy_socks5AuthPassword { = [:0] = append(, 1/* password protocol version */) = append(, uint8(len(.user))) = append(, .user...) = append(, uint8(len(.password))) = append(, .password...)if , := .Write(); != nil {returnerrors.New("proxy: failed to write authentication request to SOCKS5 proxy at " + .addr + ": " + .Error()) }if , := io.ReadFull(, [:2]); != nil {returnerrors.New("proxy: failed to read authentication reply from SOCKS5 proxy at " + .addr + ": " + .Error()) }if [1] != 0 {returnerrors.New("proxy: SOCKS5 proxy at " + .addr + " rejected username/password") } } = [:0] = append(, proxy_socks5Version, proxy_socks5Connect, 0/* reserved */)if := net.ParseIP(); != nil {if := .To4(); != nil { = append(, proxy_socks5IP4) = } else { = append(, proxy_socks5IP6) } = append(, ...) } else {iflen() > 255 {returnerrors.New("proxy: destination host name too long: " + ) } = append(, proxy_socks5Domain) = append(, byte(len())) = append(, ...) } = append(, byte(>>8), byte())if , := .Write(); != nil {returnerrors.New("proxy: failed to write connect request to SOCKS5 proxy at " + .addr + ": " + .Error()) }if , := io.ReadFull(, [:4]); != nil {returnerrors.New("proxy: failed to read connect reply from SOCKS5 proxy at " + .addr + ": " + .Error()) } := "unknown error"ifint([1]) < len(proxy_socks5Errors) { = proxy_socks5Errors[[1]] }iflen() > 0 {returnerrors.New("proxy: SOCKS5 proxy at " + .addr + " failed to connect: " + ) } := 0switch [3] {caseproxy_socks5IP4: = net.IPv4lencaseproxy_socks5IP6: = net.IPv6lencaseproxy_socks5Domain: , := io.ReadFull(, [:1])if != nil {returnerrors.New("proxy: failed to read domain length from SOCKS5 proxy at " + .addr + ": " + .Error()) } = int([0])default:returnerrors.New("proxy: got unknown address type " + strconv.Itoa(int([3])) + " from SOCKS5 proxy at " + .addr) }ifcap() < { = make([]byte, ) } else { = [:] }if , := io.ReadFull(, ); != nil {returnerrors.New("proxy: failed to read address from SOCKS5 proxy at " + .addr + ": " + .Error()) }// Also need to discard the port numberif , := io.ReadFull(, [:2]); != nil {returnerrors.New("proxy: failed to read port from SOCKS5 proxy at " + .addr + ": " + .Error()) }returnnil}
The pages are generated with Goldsv0.8.2. (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 @zigo_101 (reachable from the left QR code) to get the latest news of Golds.