func GetProxyTransportFunc(p *config.Proxy) func(*http.Request) (*url.URL, error) {

	proxyConfig := &httpproxy.Config{
		HTTPProxy:  p.HTTP,
		HTTPSProxy: p.HTTPS,
		NoProxy:    strings.Join(p.NoProxy, ","),
	}

	if config.Datadog.GetBool("no_proxy_nonexact_match") {
		return func(r *http.Request) (*url.URL, error) {
			return proxyConfig.ProxyFunc()(r.URL)
		}
	}

	return func(r *http.Request) (*url.URL, error) {
		url, err := func(r *http.Request) (*url.URL, error) {
			// check no_proxy list first
			for _, host := range p.NoProxy {
				if r.URL.Host == host {
					log.Debugf("URL match no_proxy list item '%s': not using any proxy", host)
					return nil, nil
				}
			}

			// check proxy by scheme
			confProxy := ""
			if r.URL.Scheme == "http" {
				confProxy = p.HTTP
			} else if r.URL.Scheme == "https" {
				confProxy = p.HTTPS
			} else {
				log.Warnf("Proxy configuration do not support scheme '%s'", r.URL.Scheme)
			}

			if confProxy != "" {
				proxyURL, err := url.Parse(confProxy)
				if err != nil {
					err := fmt.Errorf("Could not parse the proxy URL for scheme %s from configuration: %s", r.URL.Scheme, err)
					log.Error(err.Error())
					return nil, err
				}
				userInfo := ""
				if proxyURL.User != nil {
					if _, isSet := proxyURL.User.Password(); isSet {
						userInfo = "*****:*****@"
					} else {
						userInfo = "*****@"
					}
				}
				logSafeURL := r.URL.Scheme + "://" + r.URL.Host
				log.Debugf("Using proxy %s://%s%s for URL '%s'", proxyURL.Scheme, userInfo, proxyURL.Host, logSafeURL)
				return proxyURL, nil
			}

			// no proxy set for this request
			return nil, nil
		}(r)

		// Test the new proxy function to see if the behavior will change in the future
		newURL, _ := proxyConfig.ProxyFunc()(r.URL)

		if url == nil && newURL == nil {
			return url, err
		}

		logSafeURL := logSafeURLString(r.URL)

		// Print a warning if the url would ignore the proxy when no_proxy_nonexact_match is true
		if url != nil && newURL == nil {
			warnOnce(NoProxyIgnoredWarningMap, logSafeURL, "Deprecation warning: the HTTP request to %s uses proxy %s but will ignore the proxy when the Agent configuration option no_proxy_nonexact_match defaults to true in a future agent version. Please adapt the Agent’s proxy configuration accordingly", logSafeURL, url.String())
			return url, err
		}

		var newURLString string
		if newURL != nil {
			newURLString = newURL.String()
		}

		// There are no known cases that will trigger the below warnings but because they are logically possible we should still include them.

		// Print a warning if the url does not use the proxy - but will for some reason when no_proxy_nonexact_match is true
		if url == nil && newURL != nil {
			warnOnce(NoProxyUsedInFuture, logSafeURL, "Deprecation warning: the HTTP request to %s does not use a proxy but will use: %s when the Agent configuration option no_proxy_nonexact_match defaults to true in a future agent version.", logSafeURL, logSafeURLString(newURL))
			return url, err
		}

		// Print a warning if the url uses the proxy and still will when no_proxy_nonexact_match is true but for some reason is different
		if url.String() != newURLString {
			warnOnce(NoProxyChanged, logSafeURL, "Deprecation warning: the HTTP request to %s uses proxy %s but will change to %s when the Agent configuration option no_proxy_nonexact_match defaults to true", logSafeURL, url.String(), logSafeURLString(newURL))
			return url, err
		}

		return url, err
	}
}
// GetProxyTransportFunc return a proxy function for a http.Transport that
// would return the right proxy depending on the configuration.
GetProxyTransportFunc return a proxy function for a http.Transport that
would return the right proxy depending on the configuration.
// GetProxyTransportFunc return a proxy function for a http . Transport that // would return the right proxy depending on the configuration .
func GetProxyTransportFunc(p *config.Proxy) func(*http.Request) (*url.URL, error) {
	proxyConfig := &httpproxy.Config{
		HTTPProxy:  p.HTTP,
		HTTPSProxy: p.HTTPS,
		NoProxy:    strings.Join(p.NoProxy, ","),
	}
	if config.Datadog.GetBool("no_proxy_nonexact_match") {
		return func(r *http.Request) (*url.URL, error) {
			return proxyConfig.ProxyFunc()(r.URL)
		}
	}
	return func(r *http.Request) (*url.URL, error) {
		url, err := func(r *http.Request) (*url.URL, error) {
			for _, host := range p.NoProxy {
				if r.URL.Host == host {
					log.Debugf("URL match no_proxy list item '%s': not using any proxy", host)
					return nil, nil
				}
			}
			confProxy := ""
			if r.URL.Scheme == "http" {
				confProxy = p.HTTP
			} else if r.URL.Scheme == "https" {
				confProxy = p.HTTPS
			} else {
				log.Warnf("Proxy configuration do not support scheme '%s'", r.URL.Scheme)
			}
			if confProxy != "" {
				proxyURL, err := url.Parse(confProxy)
				if err != nil {
					err := fmt.Errorf("Could not parse the proxy URL for scheme %s from configuration: %s", r.URL.Scheme, err)
					log.Error(err.Error())
					return nil, err
				}
				userInfo := ""
				if proxyURL.User != nil {
					if _, isSet := proxyURL.User.Password(); isSet {
						userInfo = "*****:*****@"
					} else {
						userInfo = "*****@"
					}
				}
				logSafeURL := r.URL.Scheme + "://" + r.URL.Host
				log.Debugf("Using proxy %s://%s%s for URL '%s'", proxyURL.Scheme, userInfo, proxyURL.Host, logSafeURL)
				return proxyURL, nil
			}
			return nil, nil
		}(r)
		newURL, _ := proxyConfig.ProxyFunc()(r.URL)
		if url == nil && newURL == nil {
			return url, err
		}
		logSafeURL := logSafeURLString(r.URL)
		if url != nil && newURL == nil {
			warnOnce(NoProxyIgnoredWarningMap, logSafeURL, "Deprecation warning: the HTTP request to %s uses proxy %s but will ignore the proxy when the Agent configuration option no_proxy_nonexact_match defaults to true in a future agent version. Please adapt the Agent’s proxy configuration accordingly", logSafeURL, url.String())
			return url, err
		}
		var newURLString string
		if newURL != nil {
			newURLString = newURL.String()
		}
		if url == nil && newURL != nil {
			warnOnce(NoProxyUsedInFuture, logSafeURL, "Deprecation warning: the HTTP request to %s does not use a proxy but will use: %s when the Agent configuration option no_proxy_nonexact_match defaults to true in a future agent version.", logSafeURL, logSafeURLString(newURL))
			return url, err
		}
		if url.String() != newURLString {
			warnOnce(NoProxyChanged, logSafeURL, "Deprecation warning: the HTTP request to %s uses proxy %s but will change to %s when the Agent configuration option no_proxy_nonexact_match defaults to true", logSafeURL, url.String(), logSafeURLString(newURL))
			return url, err
		}
		return url, err
	}
}
func GetProxyTransportFunc ( p * config . Proxy ) func ( * http . Request ) ( * url . URL , error ) { proxyConfig := & httpproxy . Config { HTTPProxy : p . HTTP , HTTPSProxy : p . HTTPS , NoProxy : strings . Join ( p . NoProxy , " " ) , } if config . Datadog . GetBool ( " " ) { return func ( r * http . Request ) ( * url . URL , error ) { return proxyConfig . ProxyFunc ( ) ( r . URL ) } } return func ( r * http . Request ) ( * url . URL , error ) { url , err := func ( r * http . Request ) ( * url . URL , error ) { for _ , host := range p . NoProxy { if r . URL . Host == host { log . Debugf ( " " , host ) return nil , nil } } confProxy := " " if r . URL . Scheme == " " { confProxy = p . HTTP } else if r . URL . Scheme == " " { confProxy = p . HTTPS } else { log . Warnf ( " " , r . URL . Scheme ) } if confProxy != " " { proxyURL , err := url . Parse ( confProxy ) if err != nil { err := fmt . Errorf ( " " , r . URL . Scheme , err ) log . Error ( err . Error ( ) ) return nil , err } userInfo := " " if proxyURL . User != nil { if _ , isSet := proxyURL . User . Password ( ) ; isSet { userInfo = " " } else { userInfo = " " } } logSafeURL := r . URL . Scheme + " " + r . URL . Host log . Debugf ( " " , proxyURL . Scheme , userInfo , proxyURL . Host , logSafeURL ) return proxyURL , nil } return nil , nil } ( r ) newURL , _ := proxyConfig . ProxyFunc ( ) ( r . URL ) if url == nil && newURL == nil { return url , err } logSafeURL := logSafeURLString ( r . URL ) if url != nil && newURL == nil { warnOnce ( NoProxyIgnoredWarningMap , logSafeURL , " l gSafeURL,  u l.S t ring() ) return url , err } var newURLString string if newURL != nil { newURLString = newURL . String ( ) } if url == nil && newURL != nil { warnOnce ( NoProxyUsedInFuture , logSafeURL , " " , logSafeURL , logSafeURLString ( newURL ) ) return url , err } if url . String ( ) != newURLString { warnOnce ( NoProxyChanged , logSafeURL , " " , logSafeURL , url . String ( ) , logSafeURLString ( newURL ) ) return url , err } return url , err } }
GetProxyTransportFunc return a proxy function for a http.Transport that
would return the right proxy depending on the configuration.
GetProxyTransportFunc return a proxy function for a http . Transport that would return the right proxy depending on the configuration .
// check no_proxy list first // check proxy by scheme // no proxy set for this request // Test the new proxy function to see if the behavior will change in the future // Print a warning if the url would ignore the proxy when no_proxy_nonexact_match is true // There are no known cases that will trigger the below warnings but because they are logically possible we should still include them. // Print a warning if the url does not use the proxy - but will for some reason when no_proxy_nonexact_match is true // Print a warning if the url uses the proxy and still will when no_proxy_nonexact_match is true but for some reason is different