Upgrade to go 1.14
This commit is contained in:
		
							
								
								
									
										54
									
								
								vendor/golang.org/x/net/proxy/dial.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										54
									
								
								vendor/golang.org/x/net/proxy/dial.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -1,54 +0,0 @@
 | 
			
		||||
// Copyright 2019 The Go Authors. All rights reserved.
 | 
			
		||||
// Use of this source code is governed by a BSD-style
 | 
			
		||||
// license that can be found in the LICENSE file.
 | 
			
		||||
 | 
			
		||||
package proxy
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"context"
 | 
			
		||||
	"net"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// A ContextDialer dials using a context.
 | 
			
		||||
type ContextDialer interface {
 | 
			
		||||
	DialContext(ctx context.Context, network, address string) (net.Conn, error)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Dial works like DialContext on net.Dialer but using a dialer returned by FromEnvironment.
 | 
			
		||||
//
 | 
			
		||||
// The passed ctx is only used for returning the Conn, not the lifetime of the Conn.
 | 
			
		||||
//
 | 
			
		||||
// Custom dialers (registered via RegisterDialerType) that do not implement ContextDialer
 | 
			
		||||
// can leak a goroutine for as long as it takes the underlying Dialer implementation to timeout.
 | 
			
		||||
//
 | 
			
		||||
// A Conn returned from a successful Dial after the context has been cancelled will be immediately closed.
 | 
			
		||||
func Dial(ctx context.Context, network, address string) (net.Conn, error) {
 | 
			
		||||
	d := FromEnvironment()
 | 
			
		||||
	if xd, ok := d.(ContextDialer); ok {
 | 
			
		||||
		return xd.DialContext(ctx, network, address)
 | 
			
		||||
	}
 | 
			
		||||
	return dialContext(ctx, d, network, address)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// WARNING: this can leak a goroutine for as long as the underlying Dialer implementation takes to timeout
 | 
			
		||||
// A Conn returned from a successful Dial after the context has been cancelled will be immediately closed.
 | 
			
		||||
func dialContext(ctx context.Context, d Dialer, network, address string) (net.Conn, error) {
 | 
			
		||||
	var (
 | 
			
		||||
		conn net.Conn
 | 
			
		||||
		done = make(chan struct{}, 1)
 | 
			
		||||
		err  error
 | 
			
		||||
	)
 | 
			
		||||
	go func() {
 | 
			
		||||
		conn, err = d.Dial(network, address)
 | 
			
		||||
		close(done)
 | 
			
		||||
		if conn != nil && ctx.Err() != nil {
 | 
			
		||||
			conn.Close()
 | 
			
		||||
		}
 | 
			
		||||
	}()
 | 
			
		||||
	select {
 | 
			
		||||
	case <-ctx.Done():
 | 
			
		||||
		err = ctx.Err()
 | 
			
		||||
	case <-done:
 | 
			
		||||
	}
 | 
			
		||||
	return conn, err
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										15
									
								
								vendor/golang.org/x/net/proxy/direct.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										15
									
								
								vendor/golang.org/x/net/proxy/direct.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -5,27 +5,14 @@
 | 
			
		||||
package proxy
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"context"
 | 
			
		||||
	"net"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type direct struct{}
 | 
			
		||||
 | 
			
		||||
// Direct implements Dialer by making network connections directly using net.Dial or net.DialContext.
 | 
			
		||||
// Direct is a direct proxy: one that makes network connections directly.
 | 
			
		||||
var Direct = direct{}
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
	_ Dialer        = Direct
 | 
			
		||||
	_ ContextDialer = Direct
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// Dial directly invokes net.Dial with the supplied parameters.
 | 
			
		||||
func (direct) Dial(network, addr string) (net.Conn, error) {
 | 
			
		||||
	return net.Dial(network, addr)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// DialContext instantiates a net.Dialer and invokes its DialContext receiver with the supplied parameters.
 | 
			
		||||
func (direct) DialContext(ctx context.Context, network, addr string) (net.Conn, error) {
 | 
			
		||||
	var d net.Dialer
 | 
			
		||||
	return d.DialContext(ctx, network, addr)
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										15
									
								
								vendor/golang.org/x/net/proxy/per_host.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										15
									
								
								vendor/golang.org/x/net/proxy/per_host.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -5,7 +5,6 @@
 | 
			
		||||
package proxy
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"context"
 | 
			
		||||
	"net"
 | 
			
		||||
	"strings"
 | 
			
		||||
)
 | 
			
		||||
@@ -42,20 +41,6 @@ func (p *PerHost) Dial(network, addr string) (c net.Conn, err error) {
 | 
			
		||||
	return p.dialerForRequest(host).Dial(network, addr)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// DialContext connects to the address addr on the given network through either
 | 
			
		||||
// defaultDialer or bypass.
 | 
			
		||||
func (p *PerHost) DialContext(ctx context.Context, network, addr string) (c net.Conn, err error) {
 | 
			
		||||
	host, _, err := net.SplitHostPort(addr)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	d := p.dialerForRequest(host)
 | 
			
		||||
	if x, ok := d.(ContextDialer); ok {
 | 
			
		||||
		return x.DialContext(ctx, network, addr)
 | 
			
		||||
	}
 | 
			
		||||
	return dialContext(ctx, d, network, addr)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (p *PerHost) dialerForRequest(host string) Dialer {
 | 
			
		||||
	if ip := net.ParseIP(host); ip != nil {
 | 
			
		||||
		for _, net := range p.bypassNetworks {
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										33
									
								
								vendor/golang.org/x/net/proxy/proxy.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										33
									
								
								vendor/golang.org/x/net/proxy/proxy.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -15,7 +15,6 @@ import (
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// A Dialer is a means to establish a connection.
 | 
			
		||||
// Custom dialers should also implement ContextDialer.
 | 
			
		||||
type Dialer interface {
 | 
			
		||||
	// Dial connects to the given address via the proxy.
 | 
			
		||||
	Dial(network, addr string) (c net.Conn, err error)
 | 
			
		||||
@@ -26,30 +25,21 @@ type Auth struct {
 | 
			
		||||
	User, Password string
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// FromEnvironment returns the dialer specified by the proxy-related
 | 
			
		||||
// variables in the environment and makes underlying connections
 | 
			
		||||
// directly.
 | 
			
		||||
// FromEnvironment returns the dialer specified by the proxy related variables in
 | 
			
		||||
// the environment.
 | 
			
		||||
func FromEnvironment() Dialer {
 | 
			
		||||
	return FromEnvironmentUsing(Direct)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// FromEnvironmentUsing returns the dialer specify by the proxy-related
 | 
			
		||||
// variables in the environment and makes underlying connections
 | 
			
		||||
// using the provided forwarding Dialer (for instance, a *net.Dialer
 | 
			
		||||
// with desired configuration).
 | 
			
		||||
func FromEnvironmentUsing(forward Dialer) Dialer {
 | 
			
		||||
	allProxy := allProxyEnv.Get()
 | 
			
		||||
	if len(allProxy) == 0 {
 | 
			
		||||
		return forward
 | 
			
		||||
		return Direct
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	proxyURL, err := url.Parse(allProxy)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return forward
 | 
			
		||||
		return Direct
 | 
			
		||||
	}
 | 
			
		||||
	proxy, err := FromURL(proxyURL, forward)
 | 
			
		||||
	proxy, err := FromURL(proxyURL, Direct)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return forward
 | 
			
		||||
		return Direct
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	noProxy := noProxyEnv.Get()
 | 
			
		||||
@@ -57,7 +47,7 @@ func FromEnvironmentUsing(forward Dialer) Dialer {
 | 
			
		||||
		return proxy
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	perHost := NewPerHost(proxy, forward)
 | 
			
		||||
	perHost := NewPerHost(proxy, Direct)
 | 
			
		||||
	perHost.AddFromString(noProxy)
 | 
			
		||||
	return perHost
 | 
			
		||||
}
 | 
			
		||||
@@ -89,13 +79,8 @@ func FromURL(u *url.URL, forward Dialer) (Dialer, error) {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	switch u.Scheme {
 | 
			
		||||
	case "socks5", "socks5h":
 | 
			
		||||
		addr := u.Hostname()
 | 
			
		||||
		port := u.Port()
 | 
			
		||||
		if port == "" {
 | 
			
		||||
			port = "1080"
 | 
			
		||||
		}
 | 
			
		||||
		return SOCKS5("tcp", net.JoinHostPort(addr, port), auth, forward)
 | 
			
		||||
	case "socks5":
 | 
			
		||||
		return SOCKS5("tcp", u.Host, auth, forward)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// If the scheme doesn't match any of the built-in schemes, see if it
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										10
									
								
								vendor/golang.org/x/net/proxy/socks5.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										10
									
								
								vendor/golang.org/x/net/proxy/socks5.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -17,14 +17,8 @@ import (
 | 
			
		||||
func SOCKS5(network, address string, auth *Auth, forward Dialer) (Dialer, error) {
 | 
			
		||||
	d := socks.NewDialer(network, address)
 | 
			
		||||
	if forward != nil {
 | 
			
		||||
		if f, ok := forward.(ContextDialer); ok {
 | 
			
		||||
			d.ProxyDial = func(ctx context.Context, network string, address string) (net.Conn, error) {
 | 
			
		||||
				return f.DialContext(ctx, network, address)
 | 
			
		||||
			}
 | 
			
		||||
		} else {
 | 
			
		||||
			d.ProxyDial = func(ctx context.Context, network string, address string) (net.Conn, error) {
 | 
			
		||||
				return dialContext(ctx, forward, network, address)
 | 
			
		||||
			}
 | 
			
		||||
		d.ProxyDial = func(_ context.Context, network string, address string) (net.Conn, error) {
 | 
			
		||||
			return forward.Dial(network, address)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	if auth != nil {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user